Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

how to test HTTP POST with content type text/uri-list

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For simple POST call with content type json, I'm sending it like the following from my Java code in my sendPostRequest1 method. But the second method sendPostRequest2 is somewhat different because
here I'm using two URLs, one is the main URL and other is the body URL. Also, the content type should be : Content-Type=text/uri-list

I tested it in POSTMAN and it works fine and not sure how to do it in my java code.

I won't be able to use StringEntity class here, right?
 
Rancher
Posts: 157
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This javadoc shows all possible Entity types:
https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpEntity.html

Specifically here, the ByteArrayEntity seems like it's the most dynamic: https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/entity/ByteArrayEntity.html

Can you find out the bytes that you're sending with your Postman request?
If you can, then you'll be able to re-create this in Java using this entity.
 
Sheriff
Posts: 3072
454
Android Eclipse IDE Angular Framework TypeScript Redhat MicroProfile Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jack Tauson wrote:I won't be able to use StringEntity class here, right?


What not?  A type of text/uri-list is just a multi-line text document.
 
Jack Tauson
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:

Jack Tauson wrote:I won't be able to use StringEntity class here, right?


What not?  A type of text/uri-list is just a multi-line text document.



You mean the following is fine?

                       



Where http://myurisecond is the POSTMAN body URL.

Thanks
 
Ron McLeod
Sheriff
Posts: 3072
454
Android Eclipse IDE Angular Framework TypeScript Redhat MicroProfile Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah - that idea.  To make it more generic, maybe something like this:You don't need the Accept header unless you are expecting the endpoint to return you a URL list in its response.

edittedmy message to change url-list to uri-list
Staff note (Ron McLeod):

The delimiter for Collectors#joining should actually be "\r\n"

 
Ron McLeod
Sheriff
Posts: 3072
454
Android Eclipse IDE Angular Framework TypeScript Redhat MicroProfile Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling the method with this:
Would create a request which would look like this:
 
Ron McLeod
Sheriff
Posts: 3072
454
Android Eclipse IDE Angular Framework TypeScript Redhat MicroProfile Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like text/uri-list is supposed to use CRLF to separate lines, not LFCR as I had in my example, so the  delimiter for Collectors#joining should actually be "\r\n".
 
Jack Tauson
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Calling the method with this:
Would create a request which would look like this:



Just FYI, this is how my POSTMAN request looks like

Screenshot #1:



Screenshot #2:

Screenshot 2 showing content type
 
Jack Tauson
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:It looks like text/uri-list is supposed to use CRLF to separate lines, not LFCR as I had in my example, so the  delimiter for Collectors#joining should actually be "\r\n".



Thanks. This worked perfectly fine. Appreciate your guidance.
 
Sheriff
Posts: 21919
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Would create a request which would look like this:


There will be an empty line (\r\n) between the Host header line and the body. That's how HTTP determines where headers end and the body begins.
 
Jack Tauson
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:

Ron McLeod wrote:Would create a request which would look like this:


There will be an empty line (\r\n) between the Host header line and the body. That's how HTTP determines where headers end and the body begins.



I actually didn't get any response. Also, in the above lines, where is an empty line? Thanks
 
Ron McLeod
Sheriff
Posts: 3072
454
Android Eclipse IDE Angular Framework TypeScript Redhat MicroProfile Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jack Tauson wrote:I actually didn't get any response.


What were you expecting?
 
Rob Spoor
Sheriff
Posts: 21919
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jack Tauson wrote:Also, in the above lines, where is an empty line? Thanks


It's not there, Ron forgot it.
 
Ron McLeod
Sheriff
Posts: 3072
454
Android Eclipse IDE Angular Framework TypeScript Redhat MicroProfile Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:

Jack Tauson wrote:Also, in the above lines, where is an empty line? Thanks


It's not there, Ron forgot it.


Yes - sorry, I didn't show the separator between the headers and the body.

This is what it actually looked like:

Here's the output from the od (octal dump) tool which shows everything, including the CR and LF (or NL) characters:The missing empty line is at position 96 (CR) and 97 (LF) in the message.
 
please buy this thing and then I get a fat cut of the action:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic