PostHTTPData help

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by Mr Mark, Sep 20, 2016.

  1. Mr Mark

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    I just can't get this one to work...

    Pasting "https://www.someapp.com/publicapi/a...nt=something&description=something&priority=0" into my browser works but what is the correct way to use with PostHTTPData function?

    I've tried:
    PostHTTPData('https://www.someapp.com', '/publicapi/add?apikey=1234567890abcdef&application=something&event=something&description=something&priority=0');

    PostHTTPData('https://www.someapp.com/publicapi/add', '?apikey=1234567890abcdef&application=something&event=something&description=something&priority=0');

    and a few variations to no avail.
    Any advice?

    Note - there's no spaces in the address in my code or the preview box, yet some appear in the final post??
     
    Mr Mark, Sep 20, 2016
    #1
  2. Mr Mark

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,554
    Likes Received:
    180
    Location:
    Adelaide, Australia
    If it works pasting it into a browser url field try using the GetHTTPData procedure, not PostHTTPData.
     
    Ashley, Sep 21, 2016
    #2
  3. Mr Mark

    Conformist

    Joined:
    Aug 4, 2004
    Messages:
    788
    Likes Received:
    74
    Location:
    Adelaide, South Australia
    Hi Mark

    I've looked through my code and find I have used the GET rather than the POST...

    e.g.

    GetHTTPData('http://webservice.weatherzone.com.au/rss/wx.php?lc=12495&fc=1');

    I did this a long time ago and seem to remember I had to use this method. Whist this example was 'getting' info, I had a use for posting on pvoutput.org for my solar panel data

    Cheers
     
    Conformist, Sep 21, 2016
    #3
  4. Mr Mark

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    Many thanks for pointing me in the right direction, I'm now able to send notifications via Prowl to my iDevices.

    Now, to really sort my code - is there a function to check a string and replace a space with another character? Failing that, is it possible to remove white space?

    Example 1: change "11:30 PM" to "11:30+PM"?
    Example 2: change "11:30 PM" to "11:30PM"?

    I've tried changing the time format in Windows control panel but that didn't work.
     
    Mr Mark, Sep 21, 2016
    #4
  5. Mr Mark

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,554
    Likes Received:
    180
    Location:
    Adelaide, Australia
    Unfortunately the logic engine doesn't support the encodeURL/decodeURL or String replace functions so you have to do it yourself.

    Try

    Code:
    for i := 1 to length(theString) do
      if theString[i] = ' ' then theString[i] := '+';
    or

    Code:
    repeat
      i := pos(' ', theString);
      if i > 0 then theString[i] := '+';
     until i = 0;
    Probably best to put it in a procedure so you call call it from wherever you want.
     
    Last edited by a moderator: Sep 22, 2016
    Ashley, Sep 22, 2016
    #5
  6. Mr Mark

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    Thanks Ashley, your snippet did the trick.
     
    Mr Mark, Sep 22, 2016
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.