确切何时在何处发生对特定http/s URL的请求? [英] Where and when exactly a request does takes place to a particular http/s url?

查看:85
本文介绍了确切何时在何处发生对特定http/s URL的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢大家.

让我扩大范围.我设置了一些属性并发送了一些消息.
这是我尝试做客户端的方法,但这不起作用,它会重新调整不同的异常.
服务器端是安全的.它实际上是在Tomcat上运行的servlet.

Thank you all.

Let me get wider it more. I set up some properties and send some messages.
Here how I tried to do the client side, but this doesn''t work, it retuns different exceptions.
The server side is secured. It is actually a servlet runs on Tomcat.

X509Certificate cert = X509Certificate.CreateFromCertFile(@"servlet.cer");

ServicePointManager.ServerCertificateValidationCallback =
                new System.Net.Security.RemoteCertificateValidationCallback(OnCertificateValidation); // always true

request.ClientCertificates.Add(cert);
request.ContentType = "text/text";

CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(url), "Basic", new NetworkCredential("userID", "password")); 

request.Credentials = myCache;

writer.WriteLine("Why this doesn''t work as I wished?");
return;



大家好,

确切何时在何处发生对特定http/s URL的请求?
我在这里放了示例代码:
而且效果很好.



Hallo Everybody,

Where and when exactly a request does takes place to a particular http/s url?
Here I put sample code:
And this works well.

StreamWriter writer;
StreamReader reader;

string Url = "http://localhost:1212/TestPage";

WebRequest request = WebRequest.create(Url); // ---1--- here or
request.Method = "POST";

writer = new StreamWriter(request.GetRequestStream()); // ---2--- here

WebResponse response = request.GetResponse();

reader = new StreamReader(response.GetResponseStream());

writer.Close();
rsp.Close();
req.GetRequestStream().Close();

return;

推荐答案

在您的标记2中,即request.GetRequestStream().标记1只是创建WebRequest实例.
In your mark 2 i.e request.GetRequestStream(). The mark 1 just create the WebRequest instance.


request.GetRequestStream()是发送到URL的那个.

另一个建议是:完成编写后,您需要致电writer.Close().
request.GetRequestStream() is the one which is sends to the URL.

One more suggestion: You need to call writer.Close() once you done with writing.


这篇关于确切何时在何处发生对特定http/s URL的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆