本文介绍了如何在Web服务中发布JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我如何使用c#将Json对象发布到Web服务吗?实际上,我正在尝试验证C#中的App Store交易收据.
Can any one help me please that how to post Json object to web service using c#? Actually I am trying to verify an App Store Transaction Receipt in C#.
关注此链接以了解足够的想法.
follow this link to have an enough idea.
如果您有任何想法或知识,请帮助我.
Please help me if you have some idea or knowledge.
预先感谢
推荐答案
string receiptData = "(receipt bytes here)";
string url = "https://buy.itunes.apple.com/verifyReceipt";
HttpWebRequest oneWebRequest = (HttpWebRequest)WebRequest.Create(url);
oneWebRequest.Method = "POST";
oneWebRequest.ContentType = "application/json; charset=utf-8";
string json = "{ \"receipt-data\": \"" + receiptData + "\" }";
oneWebRequest.ContentLength = json.Length;
using (System.IO.StreamWriter oneStreamWriter =
new System.IO.StreamWriter(oneWebRequest.GetRequestStream(),
System.Text.Encoding.ASCII))
{
oneStreamWriter.Write(json);
}
HttpWebResponse oneWebResponse = (HttpWebResponse)oneWebRequest.GetResponse();
// ReceiptStatus is a class with two public string properties (status & receipt)
DataContractJsonSerializer oneDataContractJsonSerializer =
new DataContractJsonSerializer(typeof(List<Product>));
ReceiptStatus oneReceiptStatus =
(ReceiptStatus) oneDataContractJsonSerializer.ReadObject(
oneWebResponse.GetResponseStream()
);
这篇关于如何在Web服务中发布JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!