Solved

Presrashop webservice PUT error

Posted on 2012-03-27
9
2,404 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
Comment Utility
"I try to update the price with PUT but I always get an error"

What is the error?
0
 

Author Comment

by:marioraposo
Comment Utility
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
Comment Utility
500 - Internal Server Error should write an event into the Event Log.
0
 

Author Comment

by:marioraposo
Comment Utility
I have changed the xml text that I am sending to the server and now I get error 400
Incorrect request
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
Comment Utility
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
Comment Utility
I solved the problem
0
 

Expert Comment

by:pablooooooooo
Comment Utility
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
Comment Utility

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

6 Experts available now in Live!

Get 1:1 Help Now