我可以從Prestashop
API獲取Xml數據,但不能將PUT/POST
Xml數據轉換爲PrestaShop
API。C#REST API客戶端Prestashop
可能有人建議,我可能會去錯了嗎?
public POST_xml()
{
Uri address = new Uri("http://.../api/countries/1");
HttpWebRequest request = WebRequest.Create("http://.../api/countries/1") as HttpWebRequest;
NetworkCredential("15PJQ4V8CXI22JVW1TKZASDF0OAYNBLA", "");
// Create the web request
request = WebRequest.Create(address) as HttpWebRequest;
// Set type to POST
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
// Create the data we want to send.
string context = "<prestashop><country><id>1</id><id_zone xlink:href=\"http://.../api/zones/1\">";
context += "1</id_zone><id_currency/><iso_code>DE</iso_code><call_prefix>49</call_prefix><active>1</active><contains_states>0</contains_states><need_identification_number>0</need_identification_number><need_zip_code>1</need_zip_code><zip_code_format>NNNNN</zip_code_format><display_tax_label>1</display_tax_label><name><language";
context += " id=\"6\" xlink:href=\"http://.../api/languages/6\">Germanyxx</language></name></country></prestashop>";
StringBuilder data = new StringBuilder();
data.Append("&context=" + HttpUtility.UrlEncode(context));
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
}