Skip to content
Advertisement

Tag: http

How to send post request in java with a JSON body

I am confused as to how to send a post request in Java with JSON parameters. I have seen many examples that use HttpPost library which I can not access. Below is my code: } class main { I am trying to pass the json in the main method (I know I am not doing it right), and was wondering

Copying Image from URL to HTTP URL

Someone is providing a S3 Presigned URL so that I can upload my images to that link. All my images are on the website. Is there a way in JAVA to copy the image URL to the new URL provided ? I am trying to do this. Seems like an overkill Answer There would be no point converting to BufferedImage

Mapping nested JSON values in a Java class

I can’t figure out how to handle nested JSON values in my Java classes. To make it simple as possible, I created four Java classes with every ‘nested level’. However, I’m trying to have all these values in one Java class. How can I do this? Json: Java classes: Answer You can club all the supporting classes in one class

Upload a file using Java 11 HttpClient to SpringBoot Server

My client upload method: My Spring Boot method that receives the file: The current error: What kind of headers can I add to ensure my Spring Boot server receives the file without errors? Answer MultipartException: Current request is not a multipart request This is telling you what’s wrong. In your code: .PUT(HttpRequest.BodyPublishers.ofFile(photo.toPath())), you are doing a PUT request with file’s

How to get access token from Spotify API? [java]

I am fairly new to programming with Java but am interested in creating a program that allows for connection to the Spotify API. I am using the Client Credential Flow authorization process but keep getting java.io.IOException: insufficient data written exception when trying to reach the access token. I cannot figure out what information I am missing to complete the request.

How to return CREATED status (201 HTTP) in ResponseEntity

There is a Spring-MVC application. In controllers, when returning the results of methods, I return via ResponseEntity<>. On success, I return (200 statutes) the OK-method. But when creating something, I would like to return the CREATED-method (201 status). I just can’t understand what kind of URL to ask in parentheses when calling through CREATED. How can this be implemented? Now

Swagger codegen generates duplicated variables

I’m trying to generate client from yaml that contains That means, accept and contentType will be present in generated method signature. On top of that, I’v configured plugin like this Still, after mvn clean install I’m getting Error:(130,31) java: variable accept is already defined in method And generated code contains I’v tried different versions of plugin (from 2.3.0 up to

Advertisement