C# C中的WebResponse超时错误#
我正在尝试使用web服务发送图像。我首先将图像转换为base64字符串,并使用web请求Post方法发送到服务器。这是我的密码C# C中的WebResponse超时错误#,c#,webrequest,C#,Webrequest,我正在尝试使用web服务发送图像。我首先将图像转换为base64字符串,并使用web请求Post方法发送到服务器。这是我的密码 try { qry = "Select ProductImage From tbl_Product where ProductOnlineID=0"; dt = db.DataTable(qry); foreach (DataRow dr in dt.Rows) { string fileName = dr["Produc
try
{
qry = "Select ProductImage From tbl_Product where ProductOnlineID=0";
dt = db.DataTable(qry);
foreach (DataRow dr in dt.Rows)
{
string fileName = dr["ProductImage"].ToString();
string storeLocation = Application.StartupPath + @"\product_image\";
if (System.IO.File.Exists(storeLocation + fileName))
{
Image image = Image.FromFile(storeLocation + fileName);
MemoryStream m = new MemoryStream();
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
string base64String = Convert.ToBase64String(imageBytes);
string url_upload_imag = @"http://Myserver/api/offline/json/1.0/index.php";
string rq = "token=" + apikey + @"&json_data={%22method%22:%22uploadProductImagesLocal%22,%22data%22:[{%22imgName%22:%22" + fileName + "%22,%22imgString%22:%22" + base64String + "%22}]}";
WebRequest request = WebRequest.Create(url_upload_imag);
request.Method = "POST";
request.ContentLength = rq.Length;
byte[] array = new UTF8Encoding().GetBytes(rq);
request.ContentType = "application/x-www-form-urlencoded";
using (Stream str = request.GetRequestStream())
{
str.Write(array, 0, array.Length);
using (WebResponse ws = request.GetResponse())
{
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(RootObject_Image));
RootObject_Image obj = (RootObject_Image)jsonSerializer.ReadObject(ws.GetResponseStream());
MessageBox.Show("Done" + fileName + obj.data);
}
}
}
}
}
catch (WebException ex)
{
MessageBox.Show("Error in Sending Image:" + ex.ToString(), "Error:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
我的问题是..当我运行应用程序时,我得到了超时错误..我已经尝试了所有设置timeout为infinite对我不起作用的方法。我的base64字符串也是正确的
Web服务是用php创建的。什么可能是错误??如果有任何错误,可能是PHP还是C#?请在发布时注意格式化代码。你的大部分代码缩进的程度超过了需要的程度。你是否使用Wireshark或类似的工具来确定你是否成功发送了请求,只是处理速度不够快?@Jon Skeet-不,我没有尝试Wireshark。我试过APIKITCHEN,效果很好。你在服务器端有日志记录吗。您能看到您的web服务器正在处理该请求吗?您是否尝试过在测试工具中运行服务器端代码,传递与从客户端代码发布的值相同的值?@Nattras:不幸的是,我们没有任何凭据可以查看服务器端。它不是我们开发的。这就是为什么我要问错误来自哪一边?首先知道这一点对我来说很重要。。