我在curl比較新,我想在C中使用curl發送字符串。另一方面,作爲服務器,我有一個使用HttpServlet監聽HTTP請求的Java程序。 當我用curl發送一些數據時,我發現服務器獲取它,但沒有發送的格式。 例如,如果我送數據: 「8D015678」 在服務器側請求內容將是:56,68,48,49,53,54,55,56 這裏是客戶機代碼(C):CURL:客戶端和服務器通信Windows c/java
int status = 0;
char * ip_to_connect = "http://127.0.0.1:5004/unilateral
const char * request = "8D015678";
status = curl_easy_setopt(curl, CURLOPT_URL, ip_to_connect);
if (!status)
{
status = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
}
if (!status)
{
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(request));
}
if (!status)
{
status = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
}
if (!status)
{
status = curl_easy_perform(curl);
}
這裏是服務器(JAVA)的解析器代碼:
System.out.println("[requestHandlerFactory] header is not Content");
int contentLength = request.getContentLength();
this.content = new byte[contentLength];
try {
ServletInputStream input = request.getInputStream();
int read = input.read(content, 0, contentLength);
System.out.println("[doPost] contentLength = " + contentLength + "data = " + content[0]);
這是否意味着我需要從ASCI到符號轉換器? 我認爲捲曲數據是按原樣傳遞的?我錯過了什麼? 如果我想要我的數據,例如。 8D015678由服務器獲取爲8D015678我應該如何發送它? 請詳細解釋數據如何傳遞以及如何處理curl中的客戶端和接收這些請求的服務器 提前致謝。希望它很清楚