J.K.A.
J.K.A.

Reputation: 7404

How to send HTTP POST request which is of type "text/xml"

I want to send the HTTP POST request which is of type "text/xml" Along with the request I am sending the Querystring value as :

"?wicket:interface=:9:XXOIForm:transactionForm:componentListPanel:componentListView:0:component:expressEntryContainer:expressEntry::IBehaviorListener:0:&wicket:pcxt=XXOIForm&random=0.48316250719134435"

Here are the few request headers I am adding manually

request.Headers.Add("Accept-Language", "en-us,en;q=0.5");
request.Headers.Add("Wicket-Ajax", "true");
request.Headers.Add("Wicket-FocusedElementId", "id1a");

This all log I logged through the HTTP Anlayzer tool.

But I am not able to bypass this request. Please suggest me Is there is any way to send the HTTP POST request which is of type "text/xml"?

Or What I need to send in request headers?

Yes I am sending the post data in Byte Stream format only See I am having following code to send post data

protected void WritePostDataToRequest(string postData)
    {

        postData = postData.Replace("/", "%2F").Replace(",", "%2C").Replace(" ", "+").Replace("!", "%21").Replace("#", "%23");
        data = encoding.GetBytes(postData);
        request.ContentLength = data.Length;
        newStream = request.GetRequestStream();
        newStream.Write(data, 0, data.Length);
        newStream.Close();
    }

Also I already added the request header content type.

Thanks in Advance...

Upvotes: 1

Views: 3669

Answers (2)

veblin
veblin

Reputation: 31

request.ContentType = 'text/xml';

Upvotes: 3

DevT
DevT

Reputation: 4933

use byte stream to send ur data:

string data="wicket:interface=:9:eligibitiyBenefitsInquiryForm:transactionForm:componentListPanel:componentListView:0:component:expressEntryContainer:expressEntry::IBehaviorListener:0:&wicket:pcxt=EligibilityBenefitInquiryPage&random=0.48316250719134435"

byte[] dataStream = Encoding.UTF8.GetBytes(data);    
string uriStr = "www.abc.com";
HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(Uri.EscapeUriString(uriStr));
rqst.KeepAlive = false;
rqst.Method = "POST";


rqst.ContentType = "application/x-www-form-urlencoded";
rqst.ContentLength = dataStream.Length;
Stream newStream = rqst.GetRequestStream();

newStream.Write(dataStream, 0, dataStream.Length);
newStream.Close();
WebResponse resp = rqst.GetResponse();

Upvotes: 1

Related Questions