Results 1 to 5 of 5

Thread: [Answers] Web service

Threaded View

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] Web service

    if you use the REST version of the service along with the search key, the geturl() function and the network request object getfile() and getdata() methods return the data in JSON format. e.g.
    Code:
    mykey = "<postcoder search key>"
    mypostcode = "CW82BA"
    
    //// REST geturl()
    ? geturl("http://ws.postcoder.com/pcw/&mykey/address/uk/&mypostcode")
    
    //// REST network request object getfile() and getdata()
    oRequest = createObject("networkrequest")
    oRequest.getfile("http://ws.postcoder.com/pcw/&mykey/address/uk/&mypostcode","myfile.json")
    
    jstring = oRequest.getdata("http://ws.postcoder.com/pcw/&mykey/address/uk/&mypostcode")
    ? jstring


    Code:
    oRequest = createObject("networkrequest")
    oRequest.getfile("http://maps.googleapis.com/maps/api/geocode/xml?address=100 valentine street 08904&sensor=false","myfilename.xml")
    and this will display the status:

    Code:
    myobject = xml_decode_file("myfilename.xml", "GeocodeResponse")
    ? myobject['status']
    For larger/more complex amounts of data I would go with NetworkRequest.



    Q:
    I'm using posturl() to test a webservice written in Lianja. When going through a firewall, I'm getting a rejection because there is no host header. So, I added the host header like so:
    Still no joy: before I start sniffing, I thought I'd ask whether posturl can handle multiple header items.

    Code:
    headers = array("type" => "Content-type: application/json","host" => "yyyyyy.xxxxxx.com:8001")
    A:
    Yes it can.
    The host should not contain the port number and it should be resolvable by DNS on the target system, Typically I just use localhost for that.
    Also You must be careful to define the HTTP headers correctly. e.g.

    Code:
    headers = array("type" => "Content-type: application/json","host" => "Host: localhost")
    Notice that the dynamic array "headers" is enumerated and each element sent in the HTTP headers. The names of the elements in the dynamic array are not important.
    Some HTTP servers can be "picky" and require proper case to be used in the headers. You can find details at the link below.
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
    Notice for example "Content-type" should be "Content-Type" (case sensitive).



    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/show...ll=1#post12352
    Last edited by josipradnik; 2016-03-16 at 03:44.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us