Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Presrashop webservice PUT error

Posted on 2012-03-27
9
Medium Priority
?
2,585 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In previous Articles, we have discussed how we can upload a file using .asmx web service and isolated storage space. Here, in continuation to the topic, I am going to discuss how we can use WCF for the same purpose. Steps: 1.Create the silverli…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

879 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