How to transmit a SOAP request with MTOM using php - php

I have searched the internet for this answer. I am giving extra details in case someone on SO has encountered this, since we are getting little to no help from those managing the soap server. Here's the challenge:
A request requires a SOAP+WSDL with an MTOM attachment. The example they give is as follows:
<ser:COREEnvelopeBatchSubmission>
<PayloadType>X12_270_Request_005010X279A1</PayloadType>
<ProcessingMode>Batch</ProcessingMode>
<PayloadID>e34d8fae-5dec-08d0-a555-00a0c55e5da1</PayloadID>
<PayloadLength>518</PayloadLength>
<TimeStamp>2015-02-01T18:42:30Z</TimeStamp>
<SenderID>110000000Z</SenderID>
<ReceiverID>MMXX</ReceiverID>
<CORERuleVersion>2.2.0</CORERuleVersion>
<CheckSum>D165797749C4909B582D2167B2195C4A25CDD584</CheckSum>
<Payload>cid:251081255115</Payload>
</ser:COREEnvelopeBatchSubmission>
The Payload (cid:251081255115) must be send as an W3C Message Transmission Optimization Mechanism (MTOM) encapsulated MIME part.
It appears most folks can do this in java. We need to do this (POST a SOAP request with MTOM attachment of an .edi file) using cURL and PHP. Has anyone ever done this successfully? Can you provide an example?

Related

PHP backend sometimes return status code 500 with HTML, how can my react front end handle this?

I'm currently using AXIOS in React to make API requests, but I ran into a problem. The API provider usually returns JSON in 2xx or 404, but other times it returns HTML error pages which makes my JSON error handling not work. It's completely random to me as the front end, as I don't know which ones return what unless I go through and test each API with faulty requests (I assume this is the backends job and document it but they won't do it so it's up to me).
I have talked to my coworker who is writing the API, but they told me they can't turn those into JSON and have to keep it as HTML as some limitations with an older PHP backend. So now I have to handle both JSON and HTML error, however, they don't tell me which ones are JSON and which is HTML. Also, I cannot read the HTML and know for sure what the error message is so I can only give a general error: ie. Resource not found. Now they told me they want to display the actual error message for debug reasons, which I can't get through HTML (or at least I don't think I can)
Is the best option for me to write in my interceptor to detect each time a status code 4xx - 5xx comes in is HTML or not? Then put it in a custom error object and assign a type so I can later tell if it's HTML or not?
I have never dealt with a whole suite of APIs that returns 2 types of error, being JSON and HTML. I wonder if anyone have dealt with it to shed some light on this.
Response, even an error response, should contain Content-Type header which in your case should be either application/json for JSON responses and text/html for HTML responses. You should always only JSON-decode responses with application/json content type. Actually axios will do that for you if a proper content type header is present on the response.
There's a chance though that your API is returning JSON with text/html content type. If that happens, you have to have some serious discussion with your backend developers and strongly insist on having proper Content-Type on all API responses.

Getting a text only response to a GET or POST

I have a VB6 application which needs to send a HTTP request to a server in order to obtain some encrypted license information (50 or so bytes).
The request can be sent using either POST or GET methods, but the response is in HTML (presumably directed at a browser) and so it is difficult to search through all the HTML to find the values I need.
What is the best way to proceed?
The server script is in PHP.
Regardless of what language the server used, if the server response is an HTML including the license information, I'm afraid there are not many choices but fetching the response and extract the license bit.

How to send C++ data to PHP with post request and what is allowed to send?

Okay, so I got a game, that needs to send some stuff from C++ to a PHP page using a post request.
My questions are:
How can I send a post request?
What kind of data can I send over to PHP? (just strings and ints or also entire collections?)
How can I send a post request?
This is normally done using an HTTP library. I've not used one in C++ myself, but cURL is popular across platforms and has [C++ bindings][1] (although the documentation seems to be undergoing migration at the moment).
There is more information on the subject in this question.
What kind of data can I send over to PHP?
Pretty much any data you like - but it has to be a data format rather then a data structure. If you want to send a collection you would need to serialise it to some format. JSON is a popular one. Binary data can be encoded using base64.
If you do use JSON you could either then add a second layer of encoding to send it application/x-www-form-urlencoded and access the raw JSON via $_POST or you can make the JSON the whole body of the POST request and get the body of the post in PHP.
The fact that you say you're sending via POST request tells me that you're using a HTTP server to serve your PHP script. In which case, you want a library that allows you to send HTTP requests. A very popular choice is libcURL. What can you send? You can send anything that a HTTP request would allow you to send. So anything you like.
You can use JSON or SOAP for sending the data. When passing small amount of data JSON is preferred. More info on JSON/SOAP
To build HTTP request consider using libcurl and eventually its c++ wrapper curlpp
You can send whatever you want to php but don't forget that all the data comming from HTTP will be string for php.
PHP can cast to some type like int with intval() or (int) but binary data will be more complex to handle.
Consider using some standars like json and REST to build a robust communication.

Using Zxing online qr code decoder using php

I am creating a website that requires me to decode qr codes. I did my research and found out that php does not natively support decoding of qr codes. So, I decided to use the webservices that provide decoding of qr codes. I came across a good webservice, Zxing, which decodes the image submitted to it. The problem that I found was that I could not find enough documentation online with regards to the usage of the Zxing webservices, like how should the parameters be passed to the url of the webservice. The url that I am to access is, http://zxing.org/w/decode.jspx,
but then how should I consume this webservice using SOAP / XML-RPC in php.
I studied the result that is returned when I click on the "Submit" button, and its a simple text document.
Please, do give me guidance as to how should I consume the Zxing webservice, are there any online documentations?
Thanks.
It's not really documented as an API since it's not an API. You are not meant to integrate for use in your own service. It's a site I run as a free courtesy to end users on the web. It's OK to send a few requests at it, but for any significant volume, please run your own.
But the HTML is pretty much all the documentation you need: you can see what URL it posts to, and what parameters it sends. It's really just a POST of image content under parameter 'f', or a GET to the same URL with parameter 'u' specifying a URL to load.
The complete source code is at http://code.google.com/p/zxing, under zxingorg/. You probably want to run your own copy, so you can control it and modify it.

HTTP Post command with XML request (PHP)

I'm working on a system which needs to integrate with an external (commercial) system. On my site, I have some information, and then that needs to be checked against the external system's records. This is done by posting an XML request.
I can't make sense of their documentation. They've given me some example xml, but I just don't know what to do with it. Can anyone help?! I can't find much online that tells me what to do.
I'm using PHP, and the request has to be POSTed via HTTPS. The xml I've been given is (roughly - can't give the full details due to security):
<?xml version="1.0" standalone="no" ?>
<request>
<request_header interface_version_no="0.2" dtd_version_no="0.2">
<client_reference>Test Client</client_reference>
</request_header>
<service_request id="1">
<session_service>
<logon_request domain_id="******" user_id="******" password="******"/>
</session_service>
</service_request>
</request>
The code above should log me in to their system. So, my questions are:
What do I actually do with this? How do I make it into a POST request?
What do I do with the response (which is also xml)? I have parsed xml before (using XSLT), but that was to display it... is there a standard way of doing it in PHP?
Thanks! Any help is appreciated. I can't find much online (well, I can find loads, but none of it seems to be specific to what I'm looking for, so I'm getting confused), so even links to the appropriate help pages would be great.
Sending HTTP request, in PHP, is generally done using the curl extension, which provides a lot of features.
See for example the page of curl_setopt(), which lists all the options that can be used with curl -- there are some in there that should help you, for instance with the POSTing stuff.
Another solution, if allow_url_fopen is enabled on your server, would be to use the stream functionnality of PHP.
You could the use the file_get_contents() function, providing custom context options -- see this page : HTTP context options (the example #1 is interesting, in your case ;-) )
If you get XML as a response, you'll have to parse that result.
This is generally done, in PHP, using either DOMDocument, if you need to modify or manipulate your XML a lot... or with SimpleXML if you just need to read the XML and extract some data from it.
Here, you'll most probably need to use the simplexml_load_string function ;-)

Categories