尝试使用Web服务和C3更新时,客户未在PrestaShop中进行更新

时间:2013-08-08 14:37:02

标签: prestashop

我是PrestaShop开发的新手,我正在使用C#开发一个应用程序,它将通过webservices与PrestaShop网站进行交互。我已经成功创建了客户,但是当我尝试使用'PUT'方法更新客户时,它会给出错误

远程服务器返回错误:(500)内部服务器错误

HttpWebRequest request =(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();

如果我犯了任何错误,请纠正。

谢谢和问候

Utpal

1 个答案:

答案 0 :(得分:0)

嗨,我认为有两个问题:

当你输入数据时,你不应该用xml =和1节点作为xml的前缀,并且xml中的xml标题在发送到PrestaShop的xml中缺失

<?xml version="1.0" encoding="UTF-8"?>
  <prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
     ....
  </prestashop>