Sei sulla pagina 1di 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

Potrebbero piacerti anche