Sample XML File:
<?xml version="1.0" encoding="utf-8" ?>
<queue>
<txt>d15869d856df1ca3a749d071921f29f8</txt>
<id>d15869d856df1ca3a749d071921f29f8</id>
</queue>
for example in iranfairco.com/getXml getXml get a file xml from external request for example from other site.
now how can send this xml to this url??
From your question i udnerstand its a simple Post or Get to a URL, hence I suppose you could use System.Net's HttpWebRequest and HttpWebResponse classes for posting data, including XML data.
Related
I'm working in a Go Lang REST API repo.
I'm wanting to build an endpoint that will take in a file (as part of the form-data, so I suppose I'll use request.FormFile('my-file-key')). This endpoint should also take in a body of a JSON model (which i suppose would be decoded with something like this:
var myData model.MyModel
json.NewDecoder(request.Body).Decode(&myData)
But I'm running into a lot of issues. Is it even possible to send both a body and a file in the form-data with a http request?
If I try to send both I get errors from FormFile saying that it can't find the file of the key name (but if I send the exact same request without a body, this error doesn't happen). I guessing it's having trouble decoding the request.
What you need is a multipart request. One part can be JSON data, and the other part the file data.
If you're using a Go client to prepare the request, you need to use the mime/multipart package to create a Writer, then use CreatePart to create the JSON part, then the file part, and submit the request to the server.
On the decoding side: since the body is JSON you cannot parse it as a form. You have to use a multipart.Reader to read from the body after you parse the headers. Again, from that reader you get a Part, and read the data from that part. You'll get two parts, one for the JSON data and one for the file data.
I am looking for a solution in which I need to make all endpoint (which return XML and Json) to return empty response and a status code.
the XML/JSON response is decided on the accept header in the request. For example someone call my api I can simply return the response from the file.
How to do this in web.config. I am looking for writing a code in rewrite/rule which check the accept header and if this is xml return the empty xml file or if it's json simple return the json file.
I want to make my rule to match the particular url constraint. for example it's all started with testing. this will be something like "^testing" (case insensitive).
so anything match with ^testing and xml return static xml, and with json return static json response.
I also want to set status code in web.config so I can track that my app is maintenance mode.
Any idea how to do this in web.config.
You can write an HttpModule that will somehow check that your website is in maintenance mode. in this case, the module will write a required HTML/Json content directly into HttpResponse and end the Response.
Alternatively, configure IIS to achieve this result.
When returning a 500 error response, i want to have a WebDAV XML response like:
<?xml version="1.0" encoding="utf-8" ?>
<D:error xmlns:D="DAV:">
<D:must-be-checked-in/>
</D:error>"""
But instead of <D:must-be-checked-in/> i need some property for "Internal server error" which i could not find in any of the related RFCs. Is there a standard webdav response for server errors? Or an empty response body is ok?
If you don't have anything more specific to tell, an empty response body is just fine.
I need to consume a asp.net web service using ColdFusion 8 and return an XML file.
I am able to communicate with asp.net service but am returned an error from the service that basically says the information I passed was not valid.
Here is a run down of my code :
<cfxml variable="soap">
<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<cfoutput> <GetSession xmlns="#stagingurl#"></cfoutput>
<strApplicationKey>myappkey</strApplicationKey>
<UID>myuserid</UID>
<arrProperties>
<Property>
<Name>IP</Name>
<Value>127.0.0.1</Value>
</Property>
</arrProperties>
<arrRoles />
</GetSession>
</soap:Body>
</soap:Envelope>
</cfxml>
<cfhttp url="#apiurl#" method="post" result="httpresponse" port="443">
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="SOAPAction" value="#mysoapaction#">
<cfhttpparam type="header" name="content-length" value="#len(trim(soap))#">
<cfhttpparam type="header" name="charset" value="utf-8">
<cfhttpparam type="Body" value="#trim(soap)#" name="FileContent"/>
</cfhttp>
<cfdump var="#GetHttpRequestData()#" label="Get Http Request Data" />
Is there a way to preview the information being sent to make sure that ColdFusion is actually sending my XML/SOAP request?
I did use #GetHttpRequestData()# to return some data and within the structure, content is "empty string" and this is where I need help. Should this be empty? This is new for me, but, I guess I expected that my information being passed to the asp.net service would be in there.
FYI - I can see the HTTP and SOAP response fine, I just can not see the request information. How do I view the Request information?
Still trying to determine if the issue is on my end, or theirs and need to gather facts at this point.
Another invaluable tool when working with web services is soapUI. That should definitely be a part of your toolkit as well. You can build your request using soapUI and check the responses. Once you have it working with soapUI you can copy your request into your ColdFusion code.
One thing that I noticed is that your are wrapping your XML in a cfxml tag. I'm not sure if that is messing with your request or not. I typically wrap my XML request in cfsavecontent tags. So you could try changing your code like this:
<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<cfoutput> <GetSession xmlns="#stagingurl#"></cfoutput>
<strApplicationKey>myappkey</strApplicationKey>
<UID>myuserid</UID>
<arrProperties>
<Property>
<Name>IP</Name>
<Value>127.0.0.1</Value>
</Property>
</arrProperties>
<arrRoles />
</GetSession>
</soap:Body>
</soap:Envelope>
</cfsavecontent>
The rest of your code can remain the same.
If you're on Windows (or have a windows machine to hand) install Fiddler and start it. It's a proxy that listens on port 8888 by default so in your cfhttp call, add proxyServer="127.0.0.1" and proxyPort="8888" and run your request again.
Just noticed that you're using port 443, so probably SSL. You can enable HTTPS decrypt Tools->Fiddler Options->HTTPS Tab->Decrypt HTTPS traffic. You may then also need to import the Certificate that Fiddler uses into your keystore.
Each request will now show up in Fiddler and you can use the request and response inspectors on the right to look at the exact data going between the servers (the Raw tab shows the data unchanged). This has saved me so many times and is now part of my standard toolkit.
In your particular case, is there a reason you're not using CreateObject("webservice","http://....") . I'm assuming that it's not playing well with a .Net-based webservice?
Also, the call to GetHttpRequestData() shows the request you made to your test page, not the HTTP call you made to the test webservice. Unfortunately, CFHTTP doesn't return any structure showing the full HTTP request details it used. I think that would be a pretty sound feature request, as at the moment, you'll have to use a tool like fiddler or wireshark to see what was sent.
Simple issue with dot net is, it cannot processs XML document created by coldfusion. To return XML to dot net, convert into string format (XMLvariable.Tostring)
param of HTTP request should be
<cfhttpparam type="Body" value="#trim(soap).ToString#" name="FileContent"/>
I have a Flex application that needs to grab reporting data from a JasperReports Server, through the JasperReports Server Web Services API. Flex Builder 3 does a nice job of generating the web services consumption code, with one exception. If you ask for a directory list or an accounting of report parameters, JR Server returns plain XML in the SOAP wrapper and Flex parses it just fine. However, if you ask for a report itself, whether in XML or PDF format, it comes back as a multipart MIME message with some descriptive XML as the first part and the report -- even if the report itself is XML -- as the second part. Flex doesn't know what to do with multipart messages and just complains about invalid XML.
Here's a sample of the response. My current strategy is do some string parsing and manage the bits individually. But does Flex have any built-in methods to handle this? (I've been unable to find any.)
------=_Part_2_27050467.1235668849951
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <0F082AF1DAF83B3077B1867B4FC8AAA6>
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:runReportResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://axis2.ws.jasperserver.jaspersoft.com">
<runReportReturn xsi:type="xsd:string"><?xml version="1.0" encoding="UTF-8"?>\n<operationResult version="2.0.1">\n\t<returnCode><![CDATA[0]]></returnCode>\n</operationResult>\n
</runReportReturn>
</ns1:runReportResponse>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_2_27050467.1235668849951
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-Id: <report>
%PDF-1.4\n%âãÏÓ\n1 0 obj <</Filter/FlateDecode/Length 29>>stream\nx+är\ná26S°00S\bIár\rá\näâ
What I am going to say is only what I believe:I may be wrong since I haven't tried this out.
I don't think you have much choice. Flex HTTPService (or whatever you are using) can offer only so many (/or so few) data formats. See here. For any custom stream you will have to retrieve it as an object and pass it through your own decoder. It appears that Flex does not do any parsing of the MIME message but depends on (which is also how browsers behave typically) the server to identify the content that is being transmitted. If the server only sends a text file but changes the content type to say audio/mpeg I think you will have the same problem. Even when Flex does know hot to handle text.
If you ever can get around to doing this experiment (with text files as MIME type video or whatever fancies you) do let us know.
Meanwhile, you can take a look at SerializationFilter and go on and add a new MIME type for PDF!
Hopefully, life will be a little easy with Flex 4 and the HTTPMultiService.