1
任何人都可以帮助我,请问如何使用c#发布Json对象到web服务?其实我试图在C#中验证App Store交易收据。如何在Web服务中发布json对象
按照此链接有足够的想法。
请帮助我,如果你有一些想法或知识。
由于提前,
任何人都可以帮助我,请问如何使用c#发布Json对象到web服务?其实我试图在C#中验证App Store交易收据。如何在Web服务中发布json对象
按照此链接有足够的想法。
请帮助我,如果你有一些想法或知识。
由于提前,
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()
);
另请参见:http://stackoverflow.com/questions/10433551/problems-sending-and-receiving-json-between -asp-net-web-service-and-asp-net-web – 2012-05-30 17:53:06
您可能需要为DataContractJsonSerializer添加对System.Runtime.Serialization的引用。 – 2012-05-31 14:43:16
什么是“产品”? – 2013-08-16 03:13:31