Solved

Presrashop webservice PUT error

Posted on 2012-03-27
9
2,433 Views
Last Modified: 2013-03-06
I am trying to use vb.net webservice to update the price of a product in a prestashop database.
I can get the actual price of the product with this:

Dim Req As WebRequest = WebRequest.Create("http://mysite.com/api/products/?display=[price]&filter[id]=[123]")
Req.Method = "GET"
Req.Credentials = New NetworkCredential("??????????????????????", "")
Dim Resp As HttpWebResponse = CType(Req.GetResponse(), HttpWebResponse)
If Resp.StatusCode = HttpStatusCode.OK Then
Dim dataStream As Stream = Resp.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim R As String = reader.ReadToEnd()
MsgBox(R)


and I get the following anwser:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<products>
<product>
      <price><![CDATA[2.51]]></price>
</product>
</products>
</prestashop>

I try to update the price with PUT but I always get an error
Can anyone give me an example to solve my problem
0
Comment
Question by:marioraposo
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37776321
"I try to update the price with PUT but I always get an error"

What is the error?
0
 

Author Comment

by:marioraposo
ID: 37776631
The error I receive is 500 (internal server error)
the way I try to execute PUT is:

Dim infile As New StreamReader("file with XML")    
Dim XmlText As String = infile.ReadToEnd
infile.Close()
Dim byteData() As Byte
byteData = UTF8Encoding.UTF8.GetBytes(XmlText)

Dim Req As WebRequest = WebRequest.Create("http://mysite.com/api/products/10047")
Req.Method = "GET"
Req.Credentials = New NetworkCredential("??????????????????????", "")
Dim Resp As HttpWebResponse = CType(Req.GetResponse(), HttpWebResponse)
If Resp.StatusCode = HttpStatusCode.OK Then
   Dim Req1 As WebRequest = WebRequest.Create("http://mysite.com/api/products/10047")
   Req1.Method = "PUT"
   Req1.Credentials = New NetworkCredential("??????????????????????", "")
   Req1.ContentLength = byteData.Length
   Dim postStream As Stream = Nothing
   postStream = Req1.GetRequestStream()
   postStream.Write(byteData, 0, byteData.Length)
   postStream.Close()
   Dim Resp1 As HttpWebResponse = CType(Req1.GetResponse(), HttpWebResponse)
   If Resp1.StatusCode = HttpStatusCode.OK Then
       MsgBox("ok")
   Else
       MsgBox(Resp1.StatusCode & vbCrLf & Resp1.StatusDescription)
   End If
end if
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37776641
500 - Internal Server Error should write an event into the Event Log.
0
 

Author Comment

by:marioraposo
ID: 37776815
I have changed the xml text that I am sending to the server and now I get error 400
Incorrect request
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 37776850
400 - Bad Request return status can mean a few things, since any errors on the server side are translated to 400.  With my WCF 4 REST Service, I try to log all exceptions.
0
 

Accepted Solution

by:
marioraposo earned 0 total points
ID: 37776987
I managed to solve the problem !
I was trying to send in the XML that I am sending together with the PUT request some fields that are not possible to change in the database.
I managed to check this with a very good Web Debbuger program

http://www.fiddler2.com/fiddler2/version.asp

Thanks anyway
0
 

Author Closing Comment

by:marioraposo
ID: 37795097
I solved the problem
0
 

Expert Comment

by:pablooooooooo
ID: 38785254
Could you tell me how you solved the problem and if possible send me the file JAVA to do, need to do the same in Java. I can do it in JAVA PHP but not how. Help please. thanks

My email is pahernandezgonzalez@gmail.com
0
 

Expert Comment

by:Runan
ID: 38958707

by: marioraposoPosted on 2012-03-28 at 07:02:31ID: 37776815
I have changed the xml text that I am sending to the server and now I get error 400
Incorrect request

I have th e same problem as you. Could you give your correction or an example with the good syntax of your xml text ?

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now