0

I would like to create a PHP script that would perform a request to an https site using the GET method. In return, I get a response in xml format. I need to be able to get the contents/save this xml.

I've tried using curl, file_get_contents, fopen but I'm getting a Bad Request (400) response. But when I try to go directly to the url, I receive the xml response. Here's the url that I'm trying to get response with:

https://tst.webservices.outsurance.co.za/SecureHost/Lead/LeadPostService.svc/SubmitAffiliateLead?xml=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22+%3F%3E%0D%0A%0D%0A%3Clead%3E%0D%0A+++%3Cmode%3ELIVE%3C%2Fmode%3E%0D%0A%09%3Ctitle%3EMrs%3C%2Ftitle%3E%0D%0A%09%3Cfirstname%3EHannah%3C%2Ffirstname%3E%0D%0A%09%3Clastname%3EDwindle%3C%2Flastname%3E%0D%0A%09%3Cid%3E1723658492165%3C%2Fid%3E%0D%0A%09%3Chomecode%3E%3C%2Fhomecode%3E%0D%0A%09%3Chometel%3E%3C%2Fhometel%3E%0D%0A%09%3Cworkcode%3E011%3C%2Fworkcode%3E%0D%0A%09%3Cworktel%3E132189%3C%2Fworktel%3E%0D%0A%09%3Cmobile%3E0824176239%3C%2Fmobile%3E%0D%0A%09%3Cemail%3Ehannahdwindle@gmail.com%3C%2Femail%3E%0D%0A%09%3Ccomment%3ETHIS+IS+A+COMMENT%3C%2Fcomment%3E%0D%0A%09%3Csource%3EUPSTART%3C%2Fsource%3E%0D%0A%09%3Cnotes%3ETHIS+I+A+NOTE%3C%2Fnotes%3E%0D%0A%09%3Clanguage%3EE%3C%2Flanguage%3E%0D%0A%09%3Cproduct%3EP%3C%2Fproduct%3E%0D%0A%3C%2Flead%3E%0D%0A+++++++++

I really don't kknow what to do now. I have tried every solution that I've seen on the internet but to no avail.

maikelsabido
  • 1,253
  • 4
  • 18
  • 37

1 Answers1

0

I wrote this response a while back. It can give you way to debug your outgoing requests.

It looks like your http client is composing a request that the receiving application doesn't like. This can be on the application level too (maybe they just don't like your variables and are returning a 400 level response). I've seen API implementers do that. There's nothing to stop the implementers from doing that.

I'd find out what the exact request is that you're sending (by that link I provided) and contact the API implementers to ensure that they're expecting that type of request.

Also, with fiddler, you can craft http requests. However, the best way to craft requests to test remote APIs is to manage every byte. You can do that by using this method (supports both HTTP and HTTPS).

Lastly, I wrote an XML wrapper to make xml modification/querying easier, if it helps you at all.

Community
  • 1
  • 1
Homer6
  • 15,034
  • 11
  • 61
  • 81