Jump to content

Search the Community

Showing results for tags 'httpclient'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 2 results

  1. Hi everyone, I am new to Delphi and object pascal in general but I am coming from a web application background with Javascript. At work i want to implement a small unit that i will be using for any interactions with resources over the network I decided to go for HttpClient. One of the tasks i had to do first was find out how i can perform requests asynchronously. Due to the fact of docwiki.Embacardero has been down for 2 weeks now i scraped the web and had a look at the unit files in System.Net.HttpClient, System.Classes and System.types . I found two nice stackoverflow articles that help me give some direction: https://stackoverflow.com/questions/69298844/how-to-use-asynchronous-tnethttpclient https://stackoverflow.com/questions/54846698/delphi-fmx-httpclient-asynchronous-post-works-in-windows-fails-in-android Finally I managed to asynchronously make a get request uses System.Net.HttpClient, System.Net.URLCLient, System.Classes, System.Types; types asyncResponse = System.Types.IAsyncResult; var client: System.Net.HttpClient.THttpClient; asyncCallback: System.Classes.TAsyncCallback; begin client := THttpClient.Create; asyncCallback := procedure(const response: asyncResponse) begin // do something with response writeln(response.contentAsString); end; client.BeginGet(asyncCallback, 'path/to/resource'); end. However the second stackoverflow article above uses another approach: HTTPResult:= HTTPClient.BeginPost(DoEndPost,edtURL.Text,Params); procedure TMainForm.DoEndPost(const AsyncResult: IAsyncResult); begin try HTTPResponse := THTTPClient.EndAsyncHTTP(AsyncResult); TThread.Synchronize(nil, procedure begin // handle result lblStatusCode.Text := HTTPResponse.StatusCode.ToString; mmoResult.Text := HTTPResponse.ContentAsString(TEncoding.UTF8); end); finally end; end; So on the above code snippet there are 2 things that make me wonder if I am not doing something right. ( I would have looked for suggestions in docwiki but unfortunately i cant) Now i know that he is using method pointer callbacks and not anonymous functions so that might be the difference. The lines that bother me are: HTTPResponse := THTTPClient.EndAsyncHTTP(AsyncResult); Should i be also invoking this method within my callback? And the second thing that is bothering me is the fact that he is using threads. Should i also be synchronizing threads? For anyone who has made it this far, Thank you very much for taking the time. Sincerely, Pavlos
  2. Mocte Sandoval

    POSTing binary data with TIdHTTP

    Hi to all I don't ask here often but now I need some help with Indy ( which I don't use often either btw ). The scenario: I need to upload "documents" ( mostly PDF, Tiff, Jpg ) usually from a file to a third party HTTP server, I am doing that perfectly fine with code like this ( just a snippet ) : var Params: TIdMultipartFormDataStream; Begin ... Params.AddFile(fileName, fullFilePath, 'application/octet-stream'); http.Post('http://x.x.x.x:8996/service', Params, responseStream); ... End The endpoint from the server side receives the file and answers with code 201 which is expected. Now the problem, there are a lot of these "documents" stored on files on disk, each of these files contain a bunch of "documents" on a propietary format, which I'm succesfully extracting as an array of bytes, I can save them as individual files with TFileStream and view them with external tools, but I need to send these individual files to the http server, so for speeding up the process I want to avoid saving them to disk, so what i would like is to send the array of bytes straight to the server, here is an snippet from the code I am using so far: procedure SendFromBytes( const buffer: array of byte ); var ... data, idBoundary: String; ... Begin ... idBoundary := '---someboundaryId'; StreamResp := TStringStream.Create('',TEncoding.UTF8); streamSrc := TMemoryStream.create; http.Request.ContentType := sContentTypeFormData + idBoundary; data := idBoundary + CRLF + 'Content-Disposition: form-data; name="'+name+'"' + CRLF + CRLF; streamSrc.Write(data[1], Length(data)); streamSrc.WriteBuffer(Buffer[0], length(Buffer)); data := CRLF + idBoundary; streamSrc.Write(data[1], Length(data)); http.Post('http://x.x.x.x:8996/service', StreamSrc, streamResp); ... End; But here I'm getting 400 Bad request, so I'm not sending the message as is expected by the server Is there an Indy guru here who can help me find the cause? Edit: I'm on Delphi XE3 Edit 2: spelling on subject
×