none
POST and redirect via WebClient

    Question

  • Hi,

    I would like to know is it possible and HOW CAN I post twice via same WebClient. What I really need is POST-ing to a specific URL, and then posting again to another instance of that URL. So it kinda goes like this: I enter something to test.com/form1 and then I post to test.com/form2 using the same credentials.

           NameValueCollection postData = new NameValueCollection() 
           { 
                  { "username", username },  //order: {"parameter name", "parameter value"}
                  { "referer", referer }
           };
    
           // client.UploadValues returns page's source as byte array (byte[])
           // so it must be transformed into a string
           string pagesource = Encoding.UTF8.GetString(client.UploadValues(urlAddress, postData));

    Thanks in advance.

    Saturday, May 25, 2019 1:49 PM

All replies

  • You best use two different instances of Webclient IMO. But you can try with one instance and see what happens. The defacto http client software is HTTPClinet(). 
    Saturday, May 25, 2019 3:21 PM
  • The problem's here, idk how can I assign two instances together. =/
    Saturday, May 25, 2019 6:37 PM
  • The problem's here, idk how can I assign two instances together. =/

    What are you talking about?
    Saturday, May 25, 2019 7:39 PM
  • Can you please show an example?

    ...that's what I tried to say.

    Saturday, May 25, 2019 8:26 PM
  • Can you please show an example?

    ...that's what I tried to say.

    I can show you an example of using Httpclient(), but this thing about using a single instance of any http client software to do multiple things in the single instance such as WebClient(), may not be viable.

    https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=netframework-4.8

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/e1a4c1c6-120f-4e76-bbde-e7ce03021f60/framework-of-c-for-json-files-communication?forum=csharpgeneral

    Saturday, May 25, 2019 10:15 PM