Sending user data to server using http protocol - java

How can we send user data to server using http protocol by using other than Query string ?

Check out the Apache Commons HttpClient libraries.

The query string is used with HTTP GET requests.
You can also use HTTP POST request.
Here is a place to start: here

Use Http Post - Xml over Http Web Service.

Here is an example on how to POST some JSON and expect JSON back using the Resty library (I'm the author yadda yadda).
import static us.monoid.web.resty.Resty.*;
Resty r = new Resty();
r.json(url, content(myJsonObject));

Related

remove http headers from response using java/camel

I need to remove the below headers from response that I sent to 3rd party.
$WSIS:
$WSPR: HTTP/1.1
$WSRA:
$WSRH:
$WSSC: http
$WSSN:
$WSSP:
Authorization:
What would be the best way to remove the HTTP headers from the response in Java or camel? We are using WAS 8.5 server.
There isa removeHeaders / removeHeader you can use. The former takes a pattern where you can remove using a wildcard pattern, eg removeHeader("$W*")
These headers are added by the WebSphere Plugin and not by Camel. Using removeHeader seems to be the only solution. The same worked for me...surely a good workaround but definitely not a solution..

Example of a Protocol Buffer being sent in http by java

You set content-type to application/x-protobuf, then you serialize the protocol buffer, and then put the binary data into an http body. Send it to server/client!
What is a standard way to program such a task in java?
You can also use Jetty HTTP client, it's as easy as
ContentResponse response = httpClient.newRequest("http://domain.com/upload")
.method(HttpMethod.POST)
.content(new InputStreamContentProvider(new FileInputStream("serialized_protocol.bin")), "application/x-protobuf")
.send();
See http://www.eclipse.org/jetty/documentation/9.4.x/http-client-api.html#http-client-content

Custom HTTP headers with XmlRpcClient And Read response header

I was wondering if anyone knows how to send custom HTTP headers using an XmlRpcClient in Java?
I see a custom header can be set using XmlRpcHttpTransport.setRequestHeader() but I don't see a way of tying this in with the XmlRpcClient itself.And I want to know how read response header. I use apache xmlrpc.Can you give me a demo. Thanks. My email :seraphyong#126.com

How to send payload data using sitebricks web client using http delete method

I am using sitebricks http client to send http requests to a rest service. My question is how to send a payload data with delete ? post method accepts data as a parameter
WebClient<SubnetId> client = web().clientOf(deleteUser()).transports(User.class).over(Json.class);
//client.post(user) <-- this is OK !
client.delete(); // <-- delete does not accepts user !!!
Ok guys, a good discussion raised in here which is somewhat the answer.

What parameters and headers we need to pass to connect to Twitter using REST API?

I am trying to connect to Twitter through REST API using Java.
I am passing the following Query Parameters using POST to
https://api.twitter.com/1/statuses/update.json.
include_entities=true
oauth_consumer_key=**********
oauth_consumer_secret=************
oauth_nonce=***********
oauth_signature_method=HMAC-SHA1
oauth_timestamp=1340329822
oauth_token=***************
oauth_version=1.0
status=test msg
What is the actual process to connect to Twitter?
First I need to get auth_token using authorize request and then issue update.json request?
What ever request I am issue I am getting
{"error":"Could not authenticate you.","request":"\/1\/statuses\/update.json"}
But I checked all my config params(keys/secrets) and they are correct.
I tried connecting with the same parameters using Twitter4J and working fine.
When I tried to invoke from REST Client Tool (http://code.google.com/a/eclipselabs.org/p/restclient-tool/) with same params its failing.
Any help?
You have to pass your oauth_* parameters in a header called "Authorization", not with the other POST parameters. It is explained in the Twitter API documentation here : https://dev.twitter.com/docs/auth/authorizing-request

Categories

Resources