Pretty print curl raw requests from saved files - php

I have a set of requests and responses saved in files as raw petitions.
The files are like this:
--MIME_Boundary
Content-ID: <root.message#cxf.apache.org>
Content-Type: application/xop+xml; type="text/xml"; charset=utf-8
Content-Transfer-Encoding: 8bit
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><ns2:LoadFileResponse xmlns:ns2="http://ws.loadfile.com/loadfile/ws/LoadFileService" xmlns:ns3="http://ws.loadfile.com/loadfile/ws/CheckFileService"><ns2:responseFile><ns2:status>wait</ns2:status><ns2:fileId>2356</ns2:fileId></ns2:responseFile></ns2:LoadFileResponse></soap:Body></soapenv:Envelope>
--MIME_Boundary--
I want to show in a blade template with syntax highlight and code formatted. I used highlight.js to show the colors in the code, but I don´t know how to reformat the code.
I need something like codebeautify.org (https://codebeautify.org/xmlviewer/cbf69d49) but inside my own code.
I tried using DomDocument, but it´s not strictly XML and throws exceptions when using loadXML.
Is there any class or package to help me?
Thank you!

Related

PHP header issue

I have set HTTP header in PHP as:
header("Content-Type: application/xml");
And I got following response:
<?xml version="1.0" encoding="utf-8"?>
<feedback>
<result>False</result>
</feedback>
But when I check headers, it says the response type is application/atom+xml . I need this in application/xml format. What could be the reason for this issue?
There's no reason why that shouldn't work. I've just tried a simple test case with that xml and it certainly works for me.
<?php
header("Content-Type: application/xml");
?><?xml version="1.0" encoding="utf-8"?>
<feedback>
<result>False</result>
</feedback>
Either there is more to your php that you're not showing us, or possibly there is something misconfigured in your server software.
Update
Based on the information you provided in your answer, I'd say you could fix this by changing your root element to anything that doesn't start with <feed. As I said in my comment, something is incorrectly interpreting this as being an Atom feed and rewriting the content-type.
That said, there are assumedly other strings (e.g. <rss) that might trigger other rewrites of the content-type, so it would be preferable if you could track down whatever system was responsible for the error and get rid of it.
I can't say what the technical explanation. But changing the XML content fixed my issue. It was a slight change. I just added a top level branch element,
<?xml version="1.0" encoding="utf-8"?>
<data>
<feedback>
<result>True</result>
</feedback>
</data>

Generating SOAP message with MTOM using php class extending SoapClient

I created a class that extends SoapClient and overrides the __doRequest() function in order to be able to add an attachement to an external webserver that uses MTOM.
Basically, before calling the parent::__doRequest(), I edit the first parameter $request in order to add the MTOM part. My problem is that I get the "Error reading XMLStreamReader".
I'm not sure if it's because my generated message has mistakes or if the SoapClient::__doRequest() detects non-xml part and throws the soapfault.
Here is my generated soap message :
Content-Type: multipart/related; boundary=MIMEBoundary4A7AE22984E7738034;
type="application/xop+xml"; start="<0.09BC7F4BE2E4L7EF1B#example.org>";
start-info="text/xml; charset=utf-8"
--MIMEBoundary2013-04-24_0
content-type: application/xop+xml; charset=utf-8; type="application/soap+xml;"
content-transfer-encoding: binary
content-id: <0.09BC7F4BE2E4L7EF1B#example.org>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1{endpoint} xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><SOAP-ENV:Header>
<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>{username}</wsse:Username>
<wsse:Password>{password}</wsse:Password>
</wsse:UsernameToken>
</wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body><ns1:creerDepot/><param1>depot2013-04-24_0</param1><param2></param2></SOAP-ENV:Body></SOAP-ENV:Envelope>
--MIMEBoundary2013-04-24_0
content-type: application/octet-stream
content-transfer-encoding: binary
content-id: <2013-04-24_0>
--MIMEBoundary2013-04-24_0--{file}
Can someone tell me if my problem come from my generated message that contains errors or if it comes from the __doRequest() that doesn't want to send it?

PHP function file_get_contents retrieves encoded information - header: "'Content-Type: image/png'"

Hi everyone I am having a bit of a problem related to the php function file_get_contents.
I used it many times and no problems but when I am trying to get some information from a particular site the information I get when I echo the result is pretty much encoded (Example: ���IHDR�).
I looked at the header of the site and instead of saying
Content-Type: text/html;
it is saying
Content-Type: image/png
How do I decode that so I can get the source code (html) of the site? The web-site when I go to it in a browser, it looks like a regular web-site: text, images nothing out of ordinary.
When I look at the source code nothing out of ordinary there either. But when I do a file_get_contents I do not get the source code like I used to get on other websites.
Any ideas?
Note: I had the same problem in the past it was encoded in GZIP and I was able to find a function to decode it but with Content-Type: image/png I do not know how to proceed.
Why not, create a basic test script to the output the returned image, tho I suspect its an image saying:
Stop scrapping my site!!! Yada Yada
header('Content-Type: image/png');
echo file_get_contents('http://example.com');
The Content-Type header tells you which content-type the requested file has, in your case it is a PNG image (image/png).
You find a description of many content-types (written in a so called mime-type specification) online, this is a nice list: fileformat.info MIME types.
As you might can imagine, it's not possible to display an image in text-form (at least not before converting it to ascii art) so you will not have much luck this time.
Check the URI if it is really the one you wanted to obtain.

I need to provide a XML file so my Android can fetch it

I really am trying to code from PHP to have a XML file. I got the code that can display items from PHPmyadmin. but how can I display those things in XML file is really my problem, I tried all the codes. I could find. But, still no luck.
While generating xml your first line in php file should be
header ("content-type: text/xml; charset=utf-8");
then use echo statement & print whatever you want within xml tags like
echo "<status>0</status>";
just follow xml standerds & test using IE will be better.

content type may be?

I have an xml file saved and this is what I want to do,
when some one click the link that contains an xml file, I want them to ask the question if they want to save or open the file.
I know there is a way to do this using http header to send and trick your brower into using the application/octet-stream mime type, but I forgot how it was done. ..
it gives me this error
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
XML document must have a top level element. Error processing resource 'file:///C:/Documents and
Try adding Content-Disposition header:
Content-Disposition: attachment; filename="yourfile.xml"
And of course, the XML Content-Type header also:
Content-type: text/xml

Categories