Solved

Presrashop webservice PUT error

Posted on 2012-03-27
9
2,492 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial will show you how to add an attribute to an XML (http://en.wikipedia.org/wiki/XML) stream returned from a Windows Communication Foundation (http://en.wikipedia.org/wiki/Windows_Communication_Foundation) (WCF) Web Service.  Some knowled…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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