Solved

Presrashop webservice PUT error

Posted on 2012-03-27
9
2,461 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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
 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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