Change HttpClients HTTP version to HTTP/1.0 - apache-httpclient-4.x

im trying to use HTTP/1.0 with Apache HttpClient 4.3, but I can't find out how. In 3.x version it was done this way:
httpClient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_0);
Thats deprecated by now. How to do it now?
Thank you.

HttpGet request = new HttpGet("/stuff");
request.setProtocolVersion(HttpVersion.HTTP_1_0);

Related

Blazor WASM C# .NET 6 Content-Disposition is not Accessible

I'm extremely confused as I've been doing web development for many years now. Granted, this is my first time using Bazor and .NET 6.
Here's a screenshot of what I'm looking at:
Can someone please tell me why I can't get the content-disposition at all?
This should be trivial, but I tried logging all of the headers on the response and I just don't see anything.
My API is returning a file using File(Stream fileStream, string contentType, string? fileDownloadName) and you can see the filename in the response header.
I finally figured it out. I wasn't able to get ANY header value until I updated my API CORS Policy as follows:
You must expose the headers. I'm not sure why you can see the headers in the response, but Blazor can't, but that's what you have to do.

How to get JSON result using ASP.NET Web API?

ASP.NET Web API 2, I am able to get JSON result on local machine but when I upload same project on server it returns only XML result. Please suggest any solution for this.
I solved it by changing content-type to application/json

Jersey Client 2 proxy and multipart support

I am trying to add proxy support to my Jersey Client.
I use org.glassfish.jersey.core:jersey-client:2.11 but I can switch to any Jersey Client 2 version.
Currently the client uses the default Jersey connector which does not support proxy AFAIK.
I have tried solution described here How to add a http proxy for Jersey2 Client
but then when sending a multipart content I get:
org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
and the WARNING in the client:
Aug 10, 2015 5:10:32 PM org.glassfish.jersey.message.internal.HeaderUtils checkHeaderChanges
WARNING: There are some request headers that have not been sent by connector [org.glassfish.jersey.apache.connector.ApacheConnector]. Probably you added those headers in WriterInterceptor or MessageBodyWriter. That feature is not supported by the connector. Please, do not modify headers in WriterInterceptor or MessageBodyWriter or use default HttpUrlConnector instead.
Unsent header changes: [MIME-Version, Content-Type]
Also Jersey Client 2 documentation mentioned the issue (https://jersey.java.net/documentation/latest/user-guide.html#d0e9179)
Warning
Do not use ApacheConnectorProvider nor GrizzlyConnectorProvider neither JettyConnectorProvider connector implementations with Jersey Multipart features. See Header modification issue warning for more details.
What is the way of configuring Jersey Client 2 to support both:
Sending multipart content (for uploading files on the server)
Proxy server support
?
PS. Maybe there is a way of adding proxy support to the default jersey connector implementation?
I figured out a way to work with apache connector(connectors other than default httpurl connector) as well as multipart feature. If I add boundary to content-type when build the request with Invocation.Builder, it works.
My code is as follows.
MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
contentType = Boundary.addBoundary(contentType); // import org.glassfish.jersey.media.multipart.Boundary;
Response response = builder.post(Entity.entity(requestPayload, contentType), Response.class);

How to determine version of http in get html?

I want to request a server by 'get' and I use this method:
http://smarttracking.ir/gprmc_receiver.php?strVar=27,0,146,1,$GPRMC,213659.000,A,3238.0007,N,05118.5837,E,36.74,274.01,170114,,,N*6A5,username1,64,5}
If you copy this in the address bar on your browser, you will get a response. But there is a problem for me. I send this by sim900 module and it doesn't support http 1.0 or 1.1 and it is less than 1 so I need to send http version by address bar if it is possible. Something like this:
http://smarttracking.ir/gprmc_receiver.php?id=1 http/1.1 strVar=27,0,146,1,$GPRMC,213659.000,A,3238.0007,N,05118.5837,E,36.74,274.01,170114,,,N*6A5,username1,64,5}
Open a socket from the sim900 module to http://smarttraking.it and send a http request in according to the standard. The format of http request offers the possibility to specify the http version.
Look this image:
format http request

get json data from a https webpage

I like to get json data from a external webpage and use this data in my Xpages.
the external website have the protocol https.
so I can't use
var http_request = new XMLHttpRequest();
http_request.open("GET","XX");
has anybody a hint for me?
Alternatively you could use JSONP for your GET request:
http://dojotoolkit.org/reference-guide/1.8/dojo/io/script.html
Get it in backend with f.e. an XPage and HttpURLConnection class. This XPage can serve the JSON data to the client so you can use XMLHttpRequest.
you can use XMLHttpRequest object for Https protocol.
see https://stackoverflow.com/a/6301294/1029621