我正在尝试通过一个身份验证请求来模仿我们习惯在为此行为设置IIS时看到的"基本身份验证请求".
URL为:https
://telematicoprova.agenziadogane.it/TelematicoServiziDiUtilitaWeb/ServiziDiUtilitaAutServlet?UC =22&SC=1&ST=2(警告:https!)
此服务器在UNIX和Java下作为应用程序服务器运行.
这是我用来连接到此服务器的代码:
CookieContainer myContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://telematicoprova.agenziadogane.it/TelematicoServiziDiUtilitaWeb/ServiziDiUtilitaAutServlet?UC=22&SC=1&ST=2");
request.Credentials = new NetworkCredential(xxx,xxx);
request.CookieContainer = myContainer;
request.PreAuthenticate = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Run Code Online (Sandbox Code Playgroud)
(我从本网站上的另一篇文章中复制了此内容).但我从服务器收到这个答案:
底层连接已关闭:发送时发生意外错误.
我想我尝试了所有可能的任务,我对C#的知识必须提供给我,但没有...
当我尝试在WebRequest对象上添加HTTP标头键/值对时,我得到以下异常:
必须使用适当的属性修改此标头
我已经尝试Headers使用Add()方法向集合中添加新值,但我仍然得到相同的异常.
webRequest.Headers.Add(HttpRequestHeader.Referer, "http://stackoverflow.com");
Run Code Online (Sandbox Code Playgroud)
我可以通过将WebRequest对象转换为HttpWebRequest并设置诸如的属性来解决这个问题httpWebReq.Referer ="http://stackoverflow.com",但这仅适用于通过属性公开的少数标头.
我想知道是否有办法通过请求远程资源来修改标头的更精细控制.
我正在编写一个程序,用于从用户提供的URL中读取内容.我的问题在于代码是这样的:
Uri uri = new Uri(url);
WebRequest webRequest = WebRequest.Create(uri);
WebResponse webResponse = webRequest.GetResponse();
ReadFrom(webResponse.GetResponseStream());
Run Code Online (Sandbox Code Playgroud)
如果提供的URL是"https://"URL,则会中断.任何人都可以帮助我更改此代码,以便它可以使用SSL加密的内容.谢谢.
我刚刚在我的.NET 2.0应用程序中运行此异常(ProtocolViolationException)(在Windows Mobile 6标准仿真器上运行).令我困惑的是,据我所知,我没有添加任何内容正文,除非我无意中以某种方式完成了它.我的代码如下(非常简单).还有什么我需要做的是说服.NET这只是一个http GET吗?
谢谢,布莱恩
//run get and grab response
WebRequest request = WebRequest.Create(get.AbsoluteUri + args);
request.Method = "GET";
Stream stream = request.GetRequestStream(); // <= explodes here
XmlTextReader reader = new XmlTextReader(stream);
Run Code Online (Sandbox Code Playgroud) 我需要从外部域获取json数据.我使用webrequest来获取网站的回复.这是代码:
var request = WebRequest.Create(url);
string text;
var response = (HttpWebResponse) request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么我不能得到json数据?
现在已经发现SSL 3容易受到POODLE攻击:
System.Net.WebRequest在连接到任何https Uri时使用哪些版本的SSL/TLS?
我使用WebRequest连接到多个第三方API.其中一个已经表示他们将阻止使用SSL 3的任何请求.但是WebRequest是.Net核心框架的一部分(使用4.5),因此它使用的版本并不明显.
我无法将数据发送到网站并在Python中获得响应.我见过类似的问题,但似乎没有一个能达到我的目标.
这是我正在尝试移植到Python的C#代码:
static void Request(Uri selectedUri)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(selectedUri);
request.ServicePoint.BindIPEndPointDelegate = BindIPEndPointCallback;
request.Method = "GET";
request.Timeout = (int)Timeout.TotalMilliseconds;
request.ReadWriteTimeout = (int)Timeout.TotalMilliseconds;
request.CachePolicy = CachePolicy;
request.UserAgent = UserAgent;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
{
string responseText = responseReader.ReadToEnd();
File.WriteAllText(UrlFileName, responseText.Trim(), Encoding.ASCII);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在Python中的尝试:
def request():
web = httplib.HTTPConnection('https://someurl.com');
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
web.request("GET", "/heartbeat.jsp", headers);
response = web.getresponse();
stream = ""; #something is wrong here
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
我正在制作一个简单的REST客户端,用于我的C#应用程序.在Windows上的.net它适用于http://和https://连接.在Ubuntu 10.10的单声道2.6.7(也用2.8测试,结果相同)只有http://有效.https:// connections在request.GetResponse()方法上抛出此异常:
Unhandled Exception: System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- …Run Code Online (Sandbox Code Playgroud) 我正在集成将使用HTTP-POST来请求和检索数据的Web服务.远程服务器需要根据RFC 2617进行基本身份验证
我的身份验证尝试失败了.
它失败了,即使我将'NetworkCredential'对象附加到'HttpWebRequest'对象的'Credentials'属性,也不会在标头中发送验证信息,即使我设置'PreAuthenticate'= true.
我错过了什么?
//使用了块
NetworkCredential netCredential = new NetworkCredential(" uid", "pwd");
Uri uri = new Uri("http://address of services");
ICredentials credentials = netCredential.GetCredential(uri, "Basic");
objRegistration.Credentials = credentials;
objRegistration.PreAuthenticate = true;
Run Code Online (Sandbox Code Playgroud) 我正在尝试通过我的应用程序登录网站.我做了什么:
首先,我弄清楚浏览器如何使用Fiddler执行授权过程.我检查了如何构建POST请求,并尝试重建它.浏览器发送4个Cookie(Google Analytics),我尝试设置它们:
CookieContainer gaCookies = new CookieContainer();
gaCookies.Add(new Cookie("__utma", "#########.###########.##########.##########.##########.#"));
gaCookies.Add(new Cookie("__utmb", "#########.#.##.##########"));
gaCookies.Add(new Cookie("__utmc", "#########"));
gaCookies.Add(new Cookie("__utmz", "#########.##########.#.#.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"));
Run Code Online (Sandbox Code Playgroud)
(刚用#替换了原始的cookie数据)
然后我用调试器完成了代码,一旦第一个gaCookies.Add被执行,应用程序就停止了
System.ArgumentException: The parameter '{0}' cannot be an empty string. Parameter name: cookie.Domain
Run Code Online (Sandbox Code Playgroud)
我想知道为什么会这样.Cookie的构造函数不需要域,我不知道在哪里可以得到这个值?
如果你们中的某个人可以帮助我,那将是非常好的.
我不是网络开发者或网络专家,所以我不太了解它.
如果没有"简短快速的答案",我是否可以从中获悉这一点?
webrequest ×10
c# ×7
.net ×3
.net-4.5 ×1
cookies ×1
credentials ×1
header ×1
http ×1
https ×1
json ×1
mono ×1
python ×1
ssl ×1
streamreader ×1
web-services ×1