views:

1172

answers:

4

Hi all,

I'm trying to post to a webpage using WebClient in C#. Somehow the parameters are not coming through. The page itself is a php page. I've tested the same page with a regular browser/html page and then it works, so I'm expecting that it is a client issue

Can anybody tell me what I might be doing wrong?

        WebClient myClient = new WebClient();
        myClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
        try
        {
            NameValueCollection keyvaluepairs = new NameValueCollection();
            keyvaluepairs.Add("request", "foo");
            byte[] responseArray = myClient.UploadValues("http://www.motio.com/test.php?id=7", "POST", keyvaluepairs);
            string response = Encoding.ASCII.GetString(responseArray);
        }
        catch (Exception e)
        {
        }
A: 

Did you try doing a GET instead of a POST just to make sure it is something wrong with the web request itself?

I did. I see the result of that test is still in the uri posted above;http://www.motio.com/test.php?id=7The get ('id') parameter was coming through.
A: 

I'm very sorry for taking up your time. After further investigation, it turned out that the url I used was using http and the server redirected me to http, losing the post variables.

A: 

Hi, would you mind to describe abit more detail on your answer? I can't get you when you said you using "http and the server redirected me to http, losing the post variables."

HH
A: 

it redirected me from http to https. The redirection caused the loss of post variables.

coen