问题
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.
http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStoreReceipts.html#//apple_ref/doc/uid/TP40008267-CH104-SW1
Please help me if you have some idea or knowledge.
Thanks in advance,
回答1:
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()
);
回答2:
try with json.Net http://james.newtonking.com/pages/json-net.aspx
来源:https://stackoverflow.com/questions/2309954/how-to-post-json-object-in-web-service