Eclipse에서 HTTPClient를 사용하여 자체 소프트웨어에 POST 요청을 생성합니다. 여기 POST 요청의 매개 변수가 수신 측에서 자동으로 변경됩니다.
내 POST 요청 코드 :import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
public class Posts {
public void sendPost() throws ClientProtocolException, IOException, AuthenticationException{
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://localhost:8080/zarr-web/command/import/BDP?deltaImport=true");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("fileName", "D:\\\\Colibri_workspace\\colibri_trunk\\zarr\\zarr-backend\\servers\\wildfly-8.2.0.Final\\bin\\presentation\\soap_automation\\BANKDIRECTORYPLUS_V3_DAILY_DELTA_20170930.txt"));
UsernamePasswordCredentials creds
= new UsernamePasswordCredentials("administrator", "administrator");
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
httppost.addHeader("Content-Type", "text/plain");
httppost.addHeader(new BasicScheme().authenticate(creds, httppost, null));
//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
try {
// do something useful
} finally {
instream.close();
}
}
}
}
하지만 송신 측에 요청을 보낼 때 요청이 "파일 이름"가 반대편에 수신 될 때 올바른 "파일 이름"그러나 전송 :
012,351,fileName에 D = % 3A % 5C % 5CColibri_workspace % 5Ccolibri_trunk % 5Czarr % 5Czarr-백엔드 5Cservers % % % 5Cwildfly-8.2.0.Final 5Cbin % 5Cpresentation % 5Csoap_automation % 5CBANKDIRECTORYPLUS_V3_DAILY_DELTA_20170930.txt
SOAPUI 소프트웨어를 사용하여 요청을 보내면 파일 이름이 보낸 것과 같습니다. 내가 여기서 뭔가를 놓치고 있니?
도와주세요.
URLEncoder.encode (파일 이름, "UTF-8")를 사용하여 파일 이름을 인코딩합니다. – Satya
여기 파일 이름이 바뀌고 있습니다. 문자가 다른 곳으로 변환되고 있습니다. 참조 용 사이트는 입니다. https://www.obkb.com/dcljr/charstxt.html – Matt
@Satya 작동하지 않습니다. 당신은 당신의 해결책을 자세히 설명해 주시겠습니까 (추신 : 답으로 써주세요). – ITguy