我在NET4中有以下代码
String ret;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST"; httpWebRequest.KeepAlive = true;
httpWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
using (var response = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (var responseStream = response.GetResponseStream())
using (var reader = new StreamReader(responseStream, Encoding.UTF8))
ret = reader.ReadToEnd();
response.Close();
}
return ret;
工作,因为它应该没有问题。问题是,当代码尝试读取服务器上的文件时,服务器还没有创建它。所以我想知道在系统尝试复制之前是否有一种好方法可以等待文件出现在服务器端。
欢呼声, ES
答案 0 :(得分:0)
READ_AGAIN:
using (var response = (HttpWebResponse)httpWebRequest.GetResponse())
{ if(response == null)
goto READ_AGAIN;
using (var responseStream = response.GetResponseStream())
using (var reader = new StreamReader(responseStream, Encoding.UTF8))
ret = reader.ReadToEnd();
response.Close();
}
答案 1 :(得分:0)
遵循Eser的建议并在服务器内进行必要的更改。现在,服务器检查是在将结果发布到客户端之前创建的临时文件。