我在下面编写了 C# 应用程序,以通过 PhoneGap Build API 更新现有应用程序。我注意到当我的 .ZIP 文件为 127kb 或更少时它可以工作。一旦达到 128kb,我就会收到 500 HTTP 响应。抱歉,API 不返回任何有关错误的详细信息,仅返回 500 响应代码。对此问题的任何帮助将不胜感激。请注意身份验证令牌、appId 和 .zip 文件位置的占位符。谢谢。
using System;
using System.IO;
using System.Net;
namespace PhoneGapBuildQuestion
{
class Program
{
static void Main(string[] args)
{
string token = "<add your token here>";
string appId = "<add your appId here>";
string zipFile = "<add full path to the application .zip file here>";
var info = new FileInfo(zipFile);
var request = (HttpWebRequest)WebRequest.Create(string.Format("https://build.phonegap.com/api/v1/apps/{0}?auth_token={1}", appId, token));
request.ContentType = "application/zip";
request.Headers["Content-disposition"] = string.Format("attachment; filename=\"{0}\"", info.Name);
request.Method = "PUT";
var reqStream = request.GetRequestStream();
var file = new FileStream(zipFile, FileMode.Open);
var bytes = new byte[32768];
int len = 0;
while((len = file.Read(bytes, 0, bytes.Length)) > 0)
reqStream.Write(bytes, 0, len);
reqStream.Close();
var response = new StreamReader(request.GetResponse().GetResponseStream());
string responseText = response.ReadToEnd();
Console.WriteLine(responseText);
Console.ReadLine();
}
}
}