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/Ve开发者_StackOverflow中文版rifyingStoreReceipts.html#//apple_ref/doc/uid/TP40008267-CH104-SW1
Please help me if you have some idea or knowledge.
Thanks in advance,
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()
);
try with json.Net http://james.newtonking.com/pages/json-net.aspx
精彩评论