drl
drl

Reputation: 841

Sending POST request with custom headers

I'm trying to send a POST request with parameters and a body (via C# for Windows Phone). In order to send parameters, I need to use application/x-www-form-urlencoded for the Content-Type header.

Only problem is the server I'm communicating with expects me to have Content-Type set to something else (a custom value).

Basically for a link in the form of ip/path/file?param1=value1&param2=value2, sent via POST with the POST body being JSON content, I need to set Content-Type to something custom, but still have the parameters sent.

Is there any conceivable way of doing this? I realize it's a bit of a paradox. Changing the server API to respond to other Content-Type headers is not possible.

Upvotes: 2

Views: 3093

Answers (2)

drl
drl

Reputation: 841

I found the answer shortly after posting the question. It seems that if I construct the URL string to include the actual parameters it works like a charm.

This is oppposed to the situation where I would add parameters problematically via HTTP Requests api.

Upvotes: 0

user1968030
user1968030

Reputation:

Some headers can be set using API properties only.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.androidlost.com/androidlost/greet");
request.ContentType = "text/x-gwt-rpc; charset=utf-8";

Upvotes: 1

Related Questions