How to make HttpWebRequest using POST mehod???

string url = "http://50.57.175.247/kiran.php";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
request.Method = "POST";
request.Headers.Add("Param1", "kiran");
request.ContentType = "application/json";
HttpWebResponse myResp = (HttpWebResponse)request.GetResponse ();

This is the code i used to make HttpRequest using post method but its working when i use GET method. The only thing is i didn't get response from server when i make request using POST method(i.e, it cant send data to server using this code)...

So i want to know how to make HttpRequest to server using POST method...Plz help me...

Posts

  • PeterDavisPeterDavis USMember ✭✭✭

    First of all, can you please edit your message so your code looks correct? Simply indent the code 4 spaces and it should get proper markup.

    Have you fixed the problem yet? The code runs from LINQPad just fine.

    If it's not, what are you getting back? You say you don't get a response from the server. Does it timeout? What's the actual error message?

    Are you seeing anything in logcat?

  • kiran.6980kiran.6980 USMember

    Thanks for the reply.. I have fixed my problem... I will post my next question as said by you...Thanks...:)

  • Hi @kiran.6980,

    Could you share how you got this issue resolved?

    I got the exception with message "Expectation Failed" when doing post.

    I created a unit test project and set the ProtocolVersion to HttpVersion.Version10, the post is OK; however if I put the code inside my PCL project, it's said there is no property ProtocolVersion and HttpVersion.Version10 cannot be accessible.

    Regards, T

Sign In or Register to comment.