Domanda

Come posso vedere HttpWebRequest oggetto come stringa prima di chiamare il metodo GetResponse? Voglio vedere il formato RAW di richiesta di qualcosa di simile a questo come in Fiddler:

Content-Type: multipart/form-data; boundary=---------------------------2600251021003 
Content-Length: 338 
-----------------------------2600251021003 Content-Disposition: form-data; name="UPLOAD_FILEName"; filename="Searchlight062210 w price.csv" Content-Type: application/vnd.ms-excel 
,,,,, 
-----------------------------2600251021003 
Content-Disposition: form-data; name="submit" 
submit 
-----------------------------2600251021003-- 

Ho provato seguente codice, ma non ha funzionato perché flusso non è leggibile.

 string GetRequestString(HttpWebRequest req)
        {
            Stream stream2 = req.GetRequestStream(); 
            StreamReader reader2 = new StreamReader(stream2);
            return reader2.ReadToEnd();  

        }
È stato utile?

Soluzione

Se è per scopi di registrazione è possibile attivare il tracciamento mettendo questo nel tuo app / web.config:

  <system.diagnostics>
    <sources>
      <source name="System.Net.Sockets" tracemode="protocolonly">
        <listeners>
          <add name="System.Net.Sockets" type="System.Diagnostics.TextWriterTraceListener" initializeData="network.log" />
        </listeners>
      </source>
    </sources>

    <switches>
      <add name="System.Net.Sockets" value="Verbose"/>
    </switches>

    <trace autoflush="true" />
  </system.diagnostics>

Eseguire il codice e sguardo al file di log generato.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top