Like the title, Postman imports JSON files normally When you load a file with Delphi Get method coding, Gets the XML format. I used the GET method code that I used well before, but I don't know what the problem is.
Oh, the source code 'idhttps.Request.CustomHeaders.Add('ContentType:application/json');' was added because the other side set it this way. :(
※I am very sorry that I asked you a question using a translator because I am a Korean who can't speak English well.
begin
idhttps := TIdHTTP.Create;
//===========================idhttp Get=========================
try
//Edit1.text := Base64Encode(Edit1.Text); //Edit1.Text값을 Base64값으로 변경
//EditBASE64.Text := stringreplace(edit1.Text,' ','+',[rfReplaceAll]); // 공백오류로인한 문자열변환
APIURL := 'URL'; //API URL
//======================SSL 처리============================
sslIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idhttps);
sslIOHandler.SSLOptions.Mode := sslmClient;
sslIOHandler.SSLOptions.Method := sslvSSLv23;
idhttps.IOHandler := sslIOHandler;
//======================SSL 처리 끝============================
//======================idhttp================================
idHttps.Request.Clear;
idhttps.Request.Method:='GET';
idhttps.Request.ContentType := 'application/json';
idhttps.Request.CustomHeaders.Add('ContentType:application/json');
idhttps.Request.CustomHeaders.Add('keycode:ACCESSCODE');
idhttps.HandleRedirects := False;
idhttps.ConnectTimeout := 10000;
idhttps.ReadTimeout := 10000;
//======================idhttp================================
//======================UTF-8설정=============================
idHttps.Request.AcceptCharSet := 'utf-8';
//======================UTF-8설정 끝=============================
idhttps.HTTPOptions := idhttps.HTTPOptions [hoNoProtocolErrorException, hoWantProtocolErrorContent];
lstream := TStringStream.Create('', TEncoding.UTF8); // TStringStream.Create('', TEncoding.UTF8);
idhttps.Get(APIURL, lStream);
Result := (lStream.DataString);
finally
idhttps.Free; //개체에서 메모리해체
end;
Edit4.Text := Result;
CodePudding user response:
You need to use the Accept
header in your request (not Content-Type
) and send application/json
. I have also seen text/json
used, too.