WebRequest sta ottenendo generato da un altro IP invece il mio sistema IP?
-
01-10-2019 - |
Domanda
Ho il seguente codice che ignorare il server proxy per la macchina locale e quindi inviare un WebRequest.
System.Net.HttpWebRequest Request;
System.Net.WebResponse Response;
System.Net.CredentialCache MyCredentialCache;
Modifica 1
//System.Net.WebProxy proxyObject = new WebProxy("http://172.24.1.87:8080",true);
string strRootURI = "http://172.24.18.240/webdav/";
string strUserName = "UsName";
string strPassword = "Pwd";
// string strDomain = "Domain";
string strQuery = "";
byte[] bytes = null;
System.IO.Stream RequestStream = null;
System.IO.Stream ResponseStream = null;
System.Xml.XmlTextReader XmlReader = null;
try
{
// Build the SQL query.
strQuery = "myWebDavVerb";
// Create a new CredentialCache object and fill it with the network
// credentials required to access the server.
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add(new System.Uri(strRootURI), "Basic", new System.Net.NetworkCredential(strUserName, strPassword));//, strDomain)
// Create the HttpWebRequest object.
Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
// Add the network credentials to the request.
Request.Credentials = MyCredentialCache;
// Request.Proxy = proxyObject;
// Specify the method.
Request.Method = "PROPFIND";
}
Ora, mentre io cercavo l'esecuzione ho ottenuto 403 errore. Così ho controllato nel registro del server e scoprire che il / richiesta HTTP 1.0 è in arrivo sotto forma di un 172.24.1.87
IP mentre il mio IP è 172.24.17.220
.
C'è un modo per evitare questo? Penso che questa sia la causa principale di 403 errore.
Si prega di aiuto. Grazie,
Subhen
Soluzione
Questo indirizzo IP è l'indirizzo del proxy ... e si sta impostando il proxy per la richiesta web per essere tale proxy.
Perché ci si può aspettare che non utilizzare il proxy?
Si noti che sei richieste bypassando a la macchina locale, non da macchina locale, se questo era il tuo punto di confusione.
EDIT: Se si vuole veramente sapere cosa sta succedendo, entrare in possesso di Wireshark che vi permetterà di vedere tutte le i pacchetti provenienti dalla macchina.
Se si desidera specificare "non usare un proxy", quindi fare qualcosa di simile:
request.Proxy = GlobalProxySelection.GetEmptyWebProxy();
Altri suggerimenti
HttpWebRequest ha un valore di default per la sua proprietà Proxy questo è sempre il risultato di WebRequest.GetSystemWebProxy () che è il proxy configurato in IE
Se non si desidera utilizzare un proxy è necessario ignorare il proxy predefinito
Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
Request.Proxy = null;