Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
REST web service
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Application:
Desktop
Miscellaneous
Thread ID:
01663216
Message ID:
01665058
Views:
89
Hi,

Try this:
m.loXMLHTTP=CREATEOBJECT("Msxml2.XMLHTTP.6.0")
=COMPROP(m.loXMLHTTP, "UTF8",1)

m.lcHost="api.predic8.de"
m.lcMethod="POST"
m.lcURL="https://api.predic8.de/shop/products/"

m.lcContent=""
m.liContent=LEN(m.lcContent)


m.loXMLHTTP.Open(m.lcMethod, m.lcURL, 'false')

m.loXMLHTTP.setRequestHeader('Host',m.lcHost)
m.loXMLHTTP.setRequestHeader('Content-Length', m.liContent)
m.loXMLHTTP.setRequestHeader('Content-type', 'application/json; charset=utf-8')
m.loXMLHTTP.setRequestHeader('Basic', STRCONV(STRCONV("username:password",9),13))
m.loXMLHTTP.send(m.lcContent)

?m.loXMLHTTP.Status
?m.loXMLHTTP.statustext
?m.loXMLHTTP.responseText
MartinaJ

>>>>>Hello all,
>>>>>
>>>>>Can you provide free code so I can access a REST web service. I searched a bit and found out about Chilkat or West Wind but those are not free.
>>>>>
>>>>>I am using TwilioX and it works great. I guess that LibCurl could be used to access a web Service? Can anybody tell me how I could access a REST web service this way?
>>>>
>>>>Hi,
>>>>
>>>>COM object WinHttp.WinHttpRequest.5.1 is your friend.
>>>>REST API are HTTP GET and POST requirements.
>>>>
>>>>MartinaJ
>>>
>>>Hello Martina,
>>>
>>>I am trying to use this COM Object to test a webservice, thinking I should use something like GetResponse(). However it does not exist a method like that, only GetResponseHeader(), which is not what I would have expected.
>>>
>>>What I did so far, but without success, is to get a list as in this example:
>>>https://api.predic8.de/shop/products/
>>>
>>>So I tried it like the following:
>>>
>>>req = CreateObject("WinHttp.WinHttpResponse.5.1")
>>>req.Open("POST", "https://api.predic8.de/shop/products/", .F.)
>>>req.SetRequestHeader("Content-type", "application/x-www-form-urlencoded")
>>>MESSAGEBOX(req.Send())
>>>MESSAGEBOX(req.ResponseText)
>>>
>>>
>>>Send() returns null, ResponseText contains an error, because it expected data to be sent. So I wonder if this is the complete wrong approach, or I am trying with the wrong api, or i am missing something?
>>
>>Try it with GET. ie:
>>
>>
>>clear
>>Local loXmlHttp As "Microsoft.XMLHTTP", lcUrl
>>lcUrl = "https://api.predic8.de/shop/products/"
>>
>>loXmlHttp = Newobject( "Microsoft.XMLHTTP" )
>>loXmlHttp.Open( "GET" , m.lcUrl, .F. )
>>loXmlHttp.Send( )
>>
>>
>>? loXmlHttp.Status
>>? loXmlHttp.responsetext
>>? "==================================="
>>
>>
>>PS: I would however suggest creating and using a C# based wrapper. It is very hard to write especially POST in VFP.
>
>Thanks for the tip. At first I was thinking about a C# wrapper, but then I will have to deal with more dependencies and thought it would be easier like this, because it is only one specific service that needs to be called. At least this example works without problems, so not sure how the POST will be working out.
>
>The example I need to implement needs credentials, so I wonder if there may be an issue:
>
>
>WebRequest req = WebRequest.Create(@serviceAddress);
>req.Method = "POST";
>req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("username:password"));
>HttpWebResponse resp = req.GetResponse() as HttpWebResponse; 
>
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform