Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
484 views

How To Simulate Browser HTTP POST Request and Capture Result in C# - Stack Overflow

The document asks how to simulate an HTTP POST request and capture the result in C#, as submitting data via a POST request cannot be initialized directly through the URL like a GET request. It provides an answer that the WebClient class in C# allows uploading data to a URL via the POST method, and provides an example of using WebClient to post parameters and capture the result. The example code generates a POST request with the parameters and headers needed to simulate the request programmatically.

Uploaded by

dauto_nunes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
484 views

How To Simulate Browser HTTP POST Request and Capture Result in C# - Stack Overflow

The document asks how to simulate an HTTP POST request and capture the result in C#, as submitting data via a POST request cannot be initialized directly through the URL like a GET request. It provides an answer that the WebClient class in C# allows uploading data to a URL via the POST method, and provides an example of using WebClient to post parameters and capture the result. The example code generates a POST request with the parameters and headers needed to simulate the request programmatically.

Uploaded by

dauto_nunes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

login

StackOverflowisaquestionandanswersiteforprofessionalandenthusiastprogrammers.It's100%free,no
registrationrequired.

tour

signup

help

stackoverflowcareers

Takethe2minutetour

HowtosimulatebrowserHTTPPOSTrequestandcaptureresultinC#

Letssaywehaveawebpagewithasearchinputform,whichsubmitsdatatoserverviaHTTPGET.Sothat'smeanserverreceive
searchdatathroughquerystrings.UsercanseetheURLandcanalsoinitializethisrequestbyhimself(viaURL+Querystrings).
Weallknowthat.Hereisthequestion.
WhatifthiswebpagesubmitsdatatotheserverviaHTTPPOST?Howcanuserinitializethisrequestbyhimself?
WellIknowhowtocaptureHTTPPOST(that'swhynetworksniffersarefor),buthowcanIsimulatethisHTTPPOSTrequestbymyselfin
aC#code?
c# httppost trafficsimulation

askedJan15'10at12:13
PeterStegnar
4,381

37

63

1Answer

YoucouldtakealookattheWebClientclass.Itallowsyoutopostdatatoan
arbitraryurl:
using(varclient=newWebClient())
{
vardataToPost=Encoding.Default.GetBytes("param1=value1&param2=value2");
varresult=client.UploadData("http://example.com","POST",dataToPost);
//dosomethingwiththeresult
}

Willgeneratethefollowingrequest:
POST/HTTP/1.1
Host:example.com
ContentLength:27
Expect:100continue
Connection:KeepAlive
param1=value1&param2=value2

answeredJan15'10at12:15
DarinDimitrov
583k

89

1947

2004

You might also like