?
Solved

Posting files with IdHttp

Posted on 2004-04-24
6
Medium Priority
?
15,394 Views
Last Modified: 2012-05-04
Greetings..

I'm having problems with posting files witch over 3.5mb to IIS servers with the Indy IdHttp component.
I get this error: "Socket Error # 10054 Connection reset by peer"
In this code (witch is a part of idhttp)
---------
if (ARequest.Method in [hmPost, hmPut]) then
begin
  WriteStream(ARequest.Source, True, false);  <------this line
end;
---------
I've tried to post to apche server and that works... I find this very strange because there is no request made on my iis server when my app failes.

Here is the code I use to call the IdHttp.post function:
----------
formData := TIdMultiPartFormDataStream.Create;
formData.AddFile('File',fileName,'application/octet-stream');
HttpObject.Port := Port;
response := HttpObject.Post(posturl,formData);
-----------

I'm using "indy internet direct 9.0", Delphi 7 Enterprise on Windows XP.

Hope someone can help me.

Best regards,
Thorgeir
0
Comment
Question by:poxy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:PatrickMMartin
ID: 10909916
Well, using ASP.NET (my recommendation ) it seems to work fine with Indy:
you do need to check the parameters and the form field name.
The ASP.NET file saves the request so you should be able to see where the problem is.

Check this out : you need to put the test.aspx file in an IIS virtual directory and enter the URL

MainF.pas -----

unit MainF;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    btnPost: TButton;
    ebURL: TEdit;
    WebBrowser1: TWebBrowser;
    memResponse: TMemo;
    procedure btnPostClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
 IdMultiPartFormData
 ;

procedure TForm1.btnPostClick(Sender: TObject);
var
  formData : TIdMultiPartFormDataStream;
begin

  formData := TIdMultiPartFormDataStream.Create;
  formData.AddFile('File1', 'MainF.dfm', 'text/plain');
  idHTTP1.Port := 80;
  IdHTTP1.Request.Referer := ebURL.Text;
  memResponse.Lines.Text := idHTTP1.Post(ebURL.Text, formData);
  memResponse.Lines.SaveToFile('c:\temp\response.html');
  WebBrowser1.Navigate('c:\temp\response.html');

end;

end.


MainF.dfm --------

object Form1: TForm1
  Left = 192
  Top = 108
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnPost: TButton
    Left = 8
    Top = 16
    Width = 75
    Height = 25
    Caption = 'btnPost'
    TabOrder = 0
    OnClick = btnPostClick
  end
  object ebURL: TEdit
    Left = 112
    Top = 16
    Width = 377
    Height = 21
    TabOrder = 1
    Text = 'http://localhost/IDHTTPPost/test.aspx'
  end
  object WebBrowser1: TWebBrowser
    Left = 8
    Top = 232
    Width = 641
    Height = 201
    TabOrder = 2
    ControlData = {
      4C00000040420000C61400000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
  object memResponse: TMemo
    Left = 8
    Top = 48
    Width = 633
    Height = 177
    TabOrder = 3
  end
  object IdHTTP1: TIdHTTP
    MaxLineAction = maException
    ReadTimeout = 0
    AllowCookies = True
    ProxyParams.BasicAuthentication = False
    ProxyParams.ProxyPort = 0
    Request.ContentLength = -1
    Request.ContentRangeEnd = 0
    Request.ContentRangeStart = 0
    Request.ContentType = 'text/html'
    Request.Accept = 'text/html, */*'
    Request.BasicAuthentication = False
    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
    HTTPOptions = [hoForceEncodeParams]
    Left = 112
    Top = 65520
  end
end

test.aspx -------


<%@ Page Language="C#" autoeventwireup="True" %>
<script runat="server">

    void Page_Load()
    {
      Request.SaveAs(@"c:\temp\request.txt", true);
   
       if (File1.PostedFile != null)
       {
          try
          {
             File1.PostedFile.SaveAs(@"c:\temp\" + Text1.Value);
             Span1.InnerHtml = "File uploaded successfully to <b>c:\\temp\\" +
                               Text1.Value + "</b> on the Web server";
          }
          catch (Exception exc)
          {
             Span1.InnerHtml = "Error saving file <b>c:\\temp\\" +
                               Text1.Value + "</b><br>" + exc.ToString();
          }
       }
   
    }
   
   
    void Button1_Click(object Source, EventArgs e)
    {
   
       if (Text1.Value == "")
       {
          Span1.InnerHtml = "Error: you must enter a file name";
          return;
       }
   
    }

</script>
<html>
<head>
</head>
<body>
    <h3>HtmlInputFile Sample
    </h3>
    <form enctype="multipart/form-data" runat="server">
        Select File to Upload:
        <input id="File1" type="file" runat="server" />
        <p>
            Save as filename (no path):
            <input id="Text1" type="text" value="loaded.tmp" runat="server" />
        </p>
        <p>
            <input id="Button1" type="button" value="Upload" runat="server" onserverclick="Button1_Click" />
            <span id="Span1" style="FONT: 8pt verdana" runat="server">
            <p>
            </p>
            </span>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
    </form>
</body>
</html>
0
 
LVL 1

Expert Comment

by:tanghz
ID: 10914485
How long will it take to finish uploading the full file ? I think this should be a problem with your configuation of Web Sever. Change the connection time out longer and have a try.

What is the service program on the server side to accept the uploading file?


IdHTTP1.Request.ContentType
Double chech this property from both sides. It will cause problems when not properly set up,.


0
 
LVL 4

Expert Comment

by:ceoworks
ID: 10931954
Hi, i think that it should be a problem with IIS or ASP. I don't know much about IIS but there may be a setting which defines the maximum upload file size. I developed that kind or program before which sends the files from Delphi client to the PHP script. I was using Apache as a server. I faced with the same problem(about 2MB). After changed the php.ini setting, everything worked fine.

Regards,
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:ceoworks
ID: 10931977
or it may be related with the timeout period..
0
 
LVL 2

Accepted Solution

by:
PatrickMMartin earned 1200 total points
ID: 10932875
If the web server returned a serious error (500) Indy will throw an exception (which you should see). If there was literally no response, you could find out by stepping through the Indy code that reads the response (it's a bit awful).

If there are suspicions that the file size is a problem, test with varying sizes (ASP.NET defaults to a max request of around 4Mb, I believe ). However excessice file sizes will result in an immediate HTTP response, as it will read the content-length header.
This would not lead to a connection timeout.

Is the target you are posting to working?
Can you create a simple web page with a form and an input type="file" to attempt to post to it by hand?
0
 

Author Comment

by:poxy
ID: 10939134
Well the problem was the 4mb max file size in asp.net so thanks PatrickMMartin.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question