Sending XML in Query String - java

I am integrating USPS Web API in my Java application. I have to send a request of the form
http://production.shippingapis.com/ShippingAPI.dll?API=CityStateLookup&XML=<CityStateLookupRequest%20USERID="XXXNORTH3110"> <ZipCode ID= "0"> <Zip5>22102</Zip5> </ZipCode> </CityStateLookupRequest>
Now hitting this on the browser works fine. But using this from the JAVA code breaks. How can I send XML in the Query String?

Why you should use POST to send this type of data: http://www.w3schools.com/tags/ref_httpmethods.asp
In the POST body you don't need to encode the XML, you just need to set the correct content type "application/xml". Of course that only applies if it is valid XML and does not contain char are not allowed by XML standard.

Related

how to retreive data(present in JSON or anyother format) from a url in springboot?

I want to hit a URL which contains data, i want to retreive this data using spring boot and convert it to AVRO format. data needs to be picked up in JSON format
data and url in one sentence raises alarm. Unless you have a particular need (usually legacy reasons) to use URL to send data, use requestbody for sending the data.
Remember, many browsers will have URL character limit even though http protocol doesn't talk about any
If you are adamant about sending Jsondata using url, either look into base64encode it and send and then base64decode it on serverside.
Or do URL encoding and Decoding . Because there is a highchance that the data might not be URL-safe

How to change web script to a set response format instead of allowing negotiation?

I just created a web script to get the ticket of Alfresco Share.
Created getticket.get.desc.xml
<webscript>
<shortname>Get User Ticket</shortname>
<description>Personalized greeting</description>
<url>/getticket</url>
<authentication>user</authentication>
<negotiate accept="text/html">html</negotiate>
<negotiate accept="application/json">json</negotiate>
</webscript>
Created getticket.get.html.ftl (Plain Text)
${session.getTicket()}
I am trying to access to it from a Java page. The request is missing some parameters that the web script requires to negotiate the response format. So I need to change my web script to a set response format instead of allowing negotiation. How can I do this?
You can set response format by replacing your negotiation tag lines with following.
extension
There are various response types allowed you can mention one of them json,html,atom are few examples.

SOAP to XML conversion and sending it in response object

I am new to webservices,some how i managed to host a service with metro.With the help of SOAP UI and also httpUrlConnection object i am able to get SOAP response.But my next task is to send a response with content type "application/xml".So i used httpServletResponse,but i am not getting how to extract only XML part(without SOAP envolope and SOAP header) and also how to send XML inside respose object.Whether the way in which i am doing is rite?If yes,how to proceed with next step.
There are various ways to send xml content within SOAP response. To keep wsdl and xsd simple, you may use CDATA for your xml content and parse like a string on the receiving end.
<![CDATA[YOUR XML GOES HERE]]>
If you want to parse SOAP message and extract XML then you may want to use Java API SAAJ

Send image using http

I've got the following setup. I have to send an image over http to a browser or other device. The tricky thing about the whole it is, that I have very limited control over the http-packet creation.
I only can provide the content type field and the message body as a string.
Is there a way how I could create an http-packet containing a image with this limited configuration facilities?
You need to have:
Content-Type as 'application/image'
data in body as binary
With your limitation as you can have only strings in body, an image cannot be sent in response.
You could convert your image to a base64 string: http://www.base64-image.de/

How to send special characters in ajax request in EXTJS

I have simple extjs(2.0) form and it contains dynamically generated textfields. I am sending the form parameters to servlet using ajax request. If i enter any special characters in textfield, the textfield values are coming as URL escape codes.
For Example & is represented with %26 in servlet.
Instead of using ajax request if i use form submit, it is working. Please help me to solve this issue.
Encode values to JSON before sending, and decode them on server.
If you want to send the parameters to 'GET' method then use url encoding and send.
Try looking into encodeURI() and decodeURI().
If you are using 'POST' method then normal sending only it works.

Categories