• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4356
  • Last Modified:

URLEncode - Protocol field is empty problem

When i execute the code i get this error. Any suggestions?
procedure TForm1.bClick(Sender: TObject);
 
var
   aStream: TMemoryStream;
  Params: TStringStream;
 
begin
 
  //try
    with IdHTTP1 do
    begin
      Params.WriteString(TIdURI.URLEncode('what=' + 'Lilla Firman' + '&'));
      Request.ContentType := 'application/x-www-form-urlencoded';
 
     try
       Post('http://allabolag.se/start', Params, aStream);
      except
        on E: Exception do
          showmessage('Error encountered during POST: ' + E.Message);
      end;
    end;
end;

Open in new window

0
Paer Toernell
Asked:
Paer Toernell
1 Solution
 
Eddie ShipmanAll-around developerCommented:
Use the HTTPEncode in HTTPApp instead. lso, you will get an AV when you try to set the params in your code.

procedure TForm1.Button1Click(Sender: TObject);
var
  AStream: TMemoryStream;
  Params: TStringStream;
begin
  with IdHTTP1 do
  begin
    Params := TStringStream.Create(HTTPEncode('what=' + 'Lilla Firman' + '&'));
    AStream := TMemoryStream.Create;
    try
      Request.ContentType := 'application/x-www-form-urlencoded';
      try
        Post('http://allabolag.se/start', Params, aStream);
      except
        on E: Exception do
          showmessage('Error encountered during POST: ' + E.Message);
      end;
    finally
      Params.Free;
      AStream.Free;
    end;
  end;
end;

Open in new window

0
 
Paer ToernellAuthor Commented:
Thankyou, it did fix the questions  problem but the result is not the same as when i browse manually. I give You the points and if You want to help me more pls look at http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Internet/Q_24354958.html#a24249909
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now