libcurl post 失败

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

libcurl post 失败

26 Aug 2014, 11:41

:arrow: libcurl 函数下载地址: https://github.com/RaptorX/cURL-Wrapper
---------------------------------------------------------------------------

先说一个成功的示例

比如执行命令行代码 curl.exe http://baidu.com --libcurl libcurl.txt,生成的 libcurl.txt 内容如下:
libcurl.txt
libcurl.txt 里面的代码转成 ahk 代码是这样:

Code: Select all

#include ../cURL.new

if ret := curl_global_init(){
	msgbox % "Global initialization error: " ret
	exitapp
}

msgbox % curl_version()

hnd := curl_easy_init()
curl_easy_setopt(hnd, "CURLOPT_URL", "http://baidu.com")
curl_easy_setopt(hnd, "CURLOPT_NOPROGRESS", "1L")
curl_easy_setopt(hnd, "CURLOPT_USERAGENT", "curl/7.31.0")
curl_easy_setopt(hnd, "CURLOPT_MAXREDIRS", "50L")
curl_easy_setopt(hnd, "CURLOPT_TCP_KEEPALIVE", "1L")

MsgBox, % curl_easy_perform(hnd) ; 返回 0 表示成功

curl_easy_cleanup(hnd)
cURL_Global_Cleanup()
exitapp
失败的例子

命令行代码 curl.exe "http://s8.tinypic.com/plugin/upload.php" -F "the_file=@C:\1.jpg" -F "action=upload" -F "file_type=image" --libcurl libcurl.txt
libcurl.txt

Code: Select all

#include ../cURL.new

if ret := curl_global_init(){
	msgbox % "Global initialization error: " ret
	exitapp
}

msgbox % curl_version()

; 以下几个 cURL_FormAdd 返回的值是 4,是执行失败了。
post1 := postend := 0
msgbox % cURL_FormAdd(&post1, &postend, "CURLFORM_COPYNAME,the_file,CURLFORM_FILE,C:\\1.jpg,CURLFORM_CONTENTTYPE,image/jpeg,CURLFORM_END")
msgbox % cURL_FormAdd(&post1, &postend, "CURLFORM_COPYNAME,action,CURLFORM_COPYCONTENTS,upload,CURLFORM_END")
msgbox % cURL_FormAdd(&post1, &postend, "CURLFORM_COPYNAME,file_type,CURLFORM_COPYCONTENTS,image,CURLFORM_END")

hnd := curl_easy_init()
curl_easy_setopt(hnd, "CURLOPT_URL", "http://s8.tinypic.com/plugin/upload.php")
curl_easy_setopt(hnd, "CURLOPT_NOPROGRESS", "1L")
curl_easy_setopt(hnd, "CURLOPT_HTTPPOST", post1)
curl_easy_setopt(hnd, "CURLOPT_USERAGENT", "curl/7.31.0")
curl_easy_setopt(hnd, "CURLOPT_MAXREDIRS", "50L")
curl_easy_setopt(hnd, "CURLOPT_TCP_KEEPALIVE", "1L")

MsgBox, % curl_easy_perform(hnd) ; 返回的是空

curl_global_cleanup()
curl_formfree(post1)
exitapp
:arrow: 下载测试文件
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: libcurl post 失败

04 Dec 2016, 05:15

能否增加一个下载文件到变量的示例?

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 18 guests