1
我正在尝试TestFlight的上传API来自动化构建。这里是他们的文档:https://testflightapp.com/api/doc/使用WebRequest POST参数和数据到TestFlight
这是我测试过,并已工作极简curl命令行请求:
.\curl.exe http://testflightapp.com/api/builds.json
-F [email protected]
-F api_token='myapitoken' -F team_token='myteamtoken'
-F notes='curl test'
我已经试过转换是为C#这样的:
var uploadRequest = WebRequest.Create("http://testflightapp.com/api/builds.json") as HttpWebRequest;
uploadRequest.Method = "POST";
uploadRequest.ContentType = "multipart/form-data";
var postParameters = string.Format("api_token={0}&team_token={1}¬es=autobuild&file=", TESTFLIGHT_API_TOKEN, TESTFLIGHT_TEAM_TOKEN);
var byteParameters = Encoding.UTF8.GetBytes(postParameters);
var ipaData = File.ReadAllBytes(IPA_PATH);
uploadRequest.ContentLength = byteParameters.Length + ipaData.Length;
var requestStream = uploadRequest.GetRequestStream();
requestStream.Write(byteParameters, 0, byteParameters.Length);
requestStream.Write(ipaData, 0, ipaData.Length);
requestStream.Close();
var uploadResponse = uploadRequest.GetResponse();
不幸的是在GetResponse()
我得到一个(500) Internal Server Error
,没有更多的信息。
我不确定我postParameters中的数据是否应该由'
s包装 - 我试过了。我也不知道我的内容类型是否正确。我也试过application/x-www-form-urlencoded
,但没有任何效果。
任何帮助非常感谢。
这可能会帮助你http://stackoverflow.com/questions/219827/multipart-forms-from-c-sharp-client你需要区分的部分,因为它是一个多部分请求 –
谢谢 - 关注你的链接线索把我带到restsharp,http://restsharp.org/,它允许我在13空白行中实现请求! – tenpn