如何使用方法get,post和put https页面进行调用 [英] How do I make calls with methods get, post and put a https page

查看:127
本文介绍了如何使用方法get,post和put https页面进行调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用方法调用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.

推荐答案

记住HTTP GET的内容:

GET /whatever/page.aspx?param1=value&param2=value



请注意,GET不包含HTTP正文。这很重要。使用POST,'DATA'从QueryString移动到HTTP Body,但你仍然可以在QueryString中有东西。



POST /whatever/page.aspx? optionalotherparam1 = value

内容类型:application / x-www-form-urlencoded

内容长度:25

param1 = value& param2 =值



注意Content-Type标题和Content-Length,这些很重要。



POST只是您拥有HTTP文档时的动词。 GET暗示你什么都没有。



所以,在C#中,这是一个GET:



Remember what an HTTP GET looks like under the covers:
GET /whatever/page.aspx?param1=value&param2=value

Note that the GET includes no HTTP Body. That's important. With a POST the 'DATA' moves from the QueryString into the HTTP Body, but you can still have stuff in the QueryString.

POST /whatever/page.aspx?optionalotherparam1=value
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
param1=value&param2=value

Note the Content-Type header and the Content-Length, those are important.

A POST is just the verb for when you have an HTTP document. A GET implies you got nothing.

So, in C#, here's a GET:

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页面进行调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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