You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Chilkat进行multipart/form-data文件上传失败的问题求助

Chilkat进行multipart/form-data文件上传失败的问题求助

大家好,我遇到个棘手的问题想请教各位。这段代码逻辑很简单,就是传递几个参数并上传一个文件,之前一直运行正常,但最近突然失效了。

先贴出我的代码:

//test change timeout to 30
Chilkat.Http oHTTP = new Chilkat.Http { 
    ConnectTimeout = 2, 
    ReadTimeout = 2, 
    HeartbeatMs = 250 
};

//test or live
string reqPath = "/info.php";
string reqDomain = "127.0.0.1";
int reqPort = 6348;
bool reqSSL = false;

// REM sending request to server
Chilkat.HttpRequest oReq = new Chilkat.HttpRequest { 
    Path = reqPath, 
    HttpVerb = "POST", 
    ContentType = "multipart/form-data", 
    //{"application/x-www-form-urlencoded", "application/json", "multipart/form-data"},
    Charset = "utf-8", 
    SendCharset = true 
};

//Params
oReq.AddParam("devMode", $"yep");
oReq.AddFileForUpload("installerFile", @"f:\Temp\dev image.bmp");

Chilkat.HttpResponse oRes = oHTTP.SynchronousRequest(reqDomain, reqPort, reqSSL, oReq);
string webResponse;

if(oRes == null) {
    File.WriteAllText(@"f:\Temp\ck.log", oHTTP.LastErrorXml);
    webResponse = "!fail!";
} else {
    webResponse = oRes.BodyStr;
    File.WriteAllText(@"f:\Temp\ck.res", webResponse);
    oRes.Dispose();
}

oReq.Dispose();
oHTTP.Dispose();

现在运行会抛出错误:

The server did not respond in 2000 milliseconds.

奇怪的是,如果把ContentType改成application/x-www-form-urlencoded,请求就能正常发送,但这显然不是文件上传的正确类型,完全满足不了我的需求。

更关键的是,这个问题只出现在Chilkat的最新版本11.1.0中,我回退到旧版本比如9.5.0.98时,代码又能像之前一样正常工作了。

想请教下,Chilkat在11版本中做了什么改动导致这个问题?有没有办法在新版本中解决这个问题?我不想一直停留在旧版本上,毕竟新版本应该有更多优化和修复。

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 07:08:02