我是 PrestaShop 开发的新手,我正在使用 C# 开发一个应用程序,它将通过 web 服务与 PrestaShop 网站进行交互。我已经成功创建了客户,但是当我尝试使用“PUT”方法更新客户时出现错误
远程服务器返回错误:(500) Internal Server Error
HttpWebRequest 请求 = (HttpWebRequest)WebRequest.Create("http://mysite.com/dev/prestashop/prestashop/api/customers/?display=full&filter[id]=[3]"); NetworkCredential nc = new NetworkCredential("8MMSYQ2VJIIJZKRLAVVRD50RHLP6TQSJ", "");
request.Credentials = nc;
request.Method = "PUT";
request.ContentType = "application/xml";
string str = " <customer> " +
" <id>3</id> " +
" <id_default_group >3</id_default_group> " +
" <id_lang>1</id_lang> " +
" <newsletter_date_add>0000-00-00 00:00:00</newsletter_date_add> " +
" <ip_registration_newsletter> </ip_registration_newsletter> " +
" <deleted>0</deleted> " +
" <secure_key>381ae8a5ca84102fbdd98221495ac8ec</secure_key> " +
" <passwd>abcd.1234</passwd> " +
" <lastname>SAM</lastname> " +
" <firstname>Ghosh</firstname> " +
" <email>sam@yahoo.com</email> " +
" <active>1</active> " +
" <id_gender>0</id_gender> " +
" <birthday>0000-00-00</birthday> " +
" <newsletter>0</newsletter> " +
" <optin>0</optin> " +
" <website></website><company></company><siret></siret><ape></ape> " +
" <outstanding_allow_amount>0.000000</outstanding_allow_amount> " +
" <show_public_prices>0</show_public_prices> " +
" <id_risk>0</id_risk> " +
" <max_payment_days>0</max_payment_days> " +
" <active>0</active> " +
" <note></note> " +
" <is_guest>0</is_guest><id_shop>1</id_shop><id_shop_group>1</id_shop_group>" +
"<associations><groups>" +
" <group><id>3</id></group></groups></associations> " +
" </customer> ";
byte[] byteArray = Encoding.UTF8.GetBytes("xml=" + str);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (request.HaveResponse)
{
using (Stream streamContenido = response.GetResponseStream())
{
MessageBox.Show(new StreamReader(streamContenido).ReadToEnd());
}
}
response.Close();
如果我犯了任何错误,请更正。
谢谢并恭祝安康
乌特帕尔