Skip to content

Instantly share code, notes, and snippets.

@vasilvix vasilvix/ChcApi.java
Created May 15, 2019

Embed
What would you like to do?
Пример запроса на создание новой организации
package ru.prin;
import lombok.AllArgsConstructor;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@AllArgsConstructor
class ChcApi {
private String apiUrl;
private String authToken;
private String authKey;
void addCompany(String companyName, String companyAddress, String shortName, String password,
String username, String contacts, String mobile, String mail, String telephone) {
String data = "CompanyID=-1"
+ "&CompanyName=" + companyName
+ "&CompanyAddress=" + companyAddress
+ "&ShortName=" + shortName
+ "&Password=" + password
+ "&UserName=" + username
+ "&Contacts=" + contacts
+ "&Mobile=" + mobile
+ "&Mail=" + mail
+ "&TelePhone=" + telephone;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.header("AuthToken", authToken)
.header("AuthKey", authKey)
.header("Content-Type", "application/x-www-form-urlencoded")
.uri(URI.create(apiUrl))
.POST(HttpRequest.BodyPublishers.ofString(data))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.