问题描述
如何使用方法调用get,post并将其放到Windows Phone 8.1上具有自定义https证书的页面?
如果正常的程序不起作用,则会给出404响应。
在Visual Express 2013中,我无法获得我在java / android中使用的X509Certificate类。
谢谢。
How do I make calls with methods get, post and put it to a page with custom https certificate on Windows phone 8.1?
With the normal procedure does not work gives me a 404 response.
In Visual express 2013 I can't get the X509Certificate class that I use in a java/android.
Thanks.
推荐答案
public static string HttpGet(string URI)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.Proxy = new System.Net.WebProxy(ProxyString, true); //true means no proxy
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
Here's a POST:
public static string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.Proxy = new System.Net.WebProxy(ProxyString, true);
//Add these, as we're doing a POST
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
//We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value&
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream ();
os.Write (bytes, 0, bytes.Length); //Push it out there
os.Close ();
System.Net.WebResponse resp = req.GetResponse();
if (resp== null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
我可以而且应该加入更多使用声明,但你得到了主旨。并且,还有其他方法可以使用BCL完成此操作,但这是一个。
现在,您如何伪造HTTP PostBack?使用像ieHttpHeaders这样的工具来观察真正的回发看起来是什么样的,好吧,假装它。 :)只是希望他们不需要为该页面提供唯一/加密的ViewState(通过ViewStateUserKey或EnableViewStateMac),否则你运气不好。
I could and should have put in more 'using' statements, but you get the gist. And, there are other ways to have done this with the BCL, but this is one.
Now, how would you fake an HTTP PostBack? Use a tool like ieHttpHeaders to watch what a real postback looks like, and well, fake it. :) Just hope they don't require unique/encrypted ViewState (via ViewStateUserKey or EnableViewStateMac) for that page, or you're out of luck.
这篇关于如何使用方法get,post和put https页面进行调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!