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 用三极管设计—个共射极放大电路
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示