0
我正在使用libcurl與C++通過Internet向另一臺主機(我的朋友的計算機)發送HTTP請求。現在,另一端使用Node.js腳本來接收並處理請求。 我已經嘗試過我的電腦之間的本地網絡上的代碼(包括C++和Node),並且一切正常。這是代碼,如果你想看看:C++ - 發出的請求未到達其他計算機
CURL *handle;
string response;
curl_global_init(CURL_GLOBAL_WIN32);
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, "10.10.10.10:7890"); //<= IP:PORT of the remote host
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, "This is my POST request data!!");
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_to_string);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &response);
curl_easy_perform(handle);
curl_easy_cleanup(handle);
和Node.js的代碼:
var http = require("http");
var server = http.createServer(function(request, response) {
request.on('data', function(chunk) {
console.log("We got a connection!");
console.log("Received POST data:");
console.log(chunk.toString());
});
});
server.listen(7890);
console.log("Server is listening");
正如我所說的,我的本地網絡上它工作得很好,但爲什麼它我的朋友沒有收到請求嗎?我注意到我的代碼(C++部分)在關閉之前需要一些時間,就好像它正在嘗試連接。這是一種防火牆問題嗎?我們試圖禁用它,但沒有任何改變。我們幾乎完全是網絡的新手,我們正試圖進入。
如果有人能幫助我們,請提前致謝!
'192.168.X.X'不可路由。這只是一個局域網地址。 – 2014-09-18 18:20:53
是的,我改變了這個例子,但我們當然使用連接IP。我現在要改變它 – jndok 2014-09-18 18:21:41
我看不到錯誤處理。你怎麼知道出了什麼問題...... – 2014-09-18 18:24:47