dongshi1868 2015-04-03 12:29
浏览 88

通过HTTP-POST连接到Delphi应用程序的php脚本[通过Internet]

I've written a test php script located in a remote server of mine, and I am using Delphi code to do a Http_Post to that php file.

It works perfectly when I am doing it on a local server, but fails with a

Socket Error #10061 - Connection Refused

error.

Here is the code I am using to do the Http Post :

function TForm1.doPost(Url : String): string;
var
  lHTTP: TIdHTTP;
  lParamList: TStringList;
begin
  lParamList := TStringList.Create;
  lParamList.Add('service_test=Testing Server');

  lHTTP := TIdHTTP.Create(nil);
  try
    Result := lHTTP.Post(Url, lParamList);
    prgView.StepIt;
  finally
    lHTTP.Free;
    lParamList.Free;
  end;
end;

The url is reachable fro, browser and other applications viz. [Tested with an android app with the same php script]

Url : http://pbcserver.dlinkddns.com/users/priyabrata/contest.php

Php Script :

if (isset($_POST["service_test"])){
    $val = $_POST["service_test"];
    if ($val == "Testing Server"){
        $response["Success"] = "1";
        echo (json_encode($response));
    }
    else{
        $response["Success"] = "0";
        echo (json_encode($response));
    }
}
else{
    $response["Success"] = "0";
    echo (json_encode($response));
}

New Observation :

When I run the app from within Delphi, the post doesn't work and get the above error,however when I run the created .exe from Windows like any other app, it works perfectly!

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 用PLC设计纸袋糊底机送料系统
    • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
    • ¥15 用C语言输入方程怎么
    • ¥15 网站显示不安全连接问题
    • ¥15 github训练的模型参数无法下载
    • ¥15 51单片机显示器问题
    • ¥20 关于#qt#的问题:Qt代码的移植问题
    • ¥50 求图像处理的matlab方案
    • ¥50 winform中使用edge的Kiosk模式
    • ¥15 关于#python#的问题:功能监听网页