Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

srp_com to post a http request

I need to post to a url passing a json string for the body.

I assume I can use srp_com to do this.
I've read through an earlier thread on this board. I've read through the associated blog and I've consumed the srp_com help but I'm still just guessing at how to go about it. I've used srp_com successfully before to get but never to post.

I'm trying to keep it simple to ensure I know what I'm doing but I could use some guidance please.
My code at this stage is like this
If SRP_COM(objXmlHttp, "CREATE", "Msxml2.ServerXMLHTTP.6.0") then TheError = SRP_COM(null$, "ERROR") Status = oleStatus() rv = SRP_COM(objXmlHttp, "Call", "open", "POST", theurl ) TheError = SRP_COM(null$, "ERROR") rv = SRP_COM(objXmlHttp, "Call", "send", payload ) TheError = SRP_COM(null$, "ERROR") Status = oleStatus() Result = SRP_Com(objXmlHttp, "RELEASE") end

The 'send' appears to be doing something as it takes a moment to complete and I don't get any errors but I also don't get the result I'm looking for so I was hoping for some verification of my syntax before I go any further.

TIA

Comments

  • I've added these lines after the send
    Response = SRP_COM(objXMLHTTP, "GET", "responseBody") Responsetxt = SRP_COM(objXMLHTTP, "GET", "responseText") RespStat = SRP_COM(objXMLHTTP, "GET", "status") RespStatTxt = SRP_COM(objXMLHTTP, "GET", "statusText")

    and there's an actual response telling me my body is empty so it looks like I'm on the right track.
    'payload' wasn't empty though, so have I positioned that incorrectly or should I be looking elsewhere?
    Let me rephrase that. I'll be looking elsewhere unless someone points out something I have missed.
  • may as well wack in :
    "responseCode" and "responseStatus"
  • You don't have any headers?
    "setRequestHeader"
  • About ready to depart on a flight. Is there a reason you don't use the SendHTTPRequest service?

    https://wiki.srpcs.com/display/HTTPFramework/HTTPClient_Services
  • Don that would be because that would appear to be the easy way and who wants to do that?

    Oh and I was too lazy to keep up with your HTTPFramework updates and forgot that the clientservices existed even though I had read about it some time ago.
  • Whaddya know? The SendHTTPRequest service works a treat.
  • Cool. If you are interested in figuring out what you may have been doing wrong you can scan the source code for our service. It uses SRP_COM and the same calls you were using. I just didn't try to line up your code to see what might have been going wrong.
  • Actually, in the meantime I had posted a question on the dev forum for the service I was trying to request.
    I got a "just curious but why are you trying to use that method instead of this new one?" which sounded remarkably similar to
    Is there a reason you don't use the SendHTTPRequest service?
    So, with the switch to HTTPClient_services I also switched to the newer approach of the service I was after.

    In truth I think their documentation of the legacy approach was not quite right but they've moved on and aren't going to fix it. I had received the same error when attempting via Postman so it wasn't the srp_com calls specifically.

    No doubt though, the SendHTTPRequest service made it simpler to implement their new model.
  • "dev forum"? Is this the dev forum for the web service you are trying to connect to?
  • Yes. Integrating with Geckoboard
Sign In or Register to comment.