[英]Get http 500 in a Azure worker role http request
我有一个运行1个工作角色和1个Web角色的Azure Web服务,这些角色设置为处于Azure专用网络中。
worker角色与我们的数据库执行一些同步工作,该数据库正在从许多API和服务器下载报告文件,然后将其同步到我们的数据库,出于某种原因(10个中的1个)API http请求在云中返回HTTP错误500,但是当我在机器上对其进行调试时,它可以正常工作,并且我在EC2(AWS)aspx网站上运行的代码与在AWS上运行的数据库所做的相同,这很好。
这是执行该任务的代码(失败的代码):
public void GenerateReport(DateTime start, DateTime end)
{
string URL = this._cj_url;
URL = string.Format(URL, start.ToString("yyyy-MM-dd"), end.ToString("yyyy-MM-dd"));
RequestState myRequestState = new RequestState();
myRequestState.request = (HttpWebRequest)WebRequest.Create(URL);
myRequestState.from = start;
myRequestState.to = end;
myRequestState.prefix = "CJ";
myRequestState.ext = "xml";
try
{
myRequestState.request.Headers.Add("authorization:" + _devKey);
myRequestState.request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1";
HttpWebRequest myHttpWebRequest = myRequestState.request;
myRequestState.response = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Read the response into a Stream object.
Stream responseStream = myRequestState.response.GetResponseStream();
myRequestState.streamResponse = responseStream;
//' Get response
myRequestState.response = (HttpWebResponse)myRequestState.request.GetResponse();
//' Get the response stream into a reader
StreamReader reader = new StreamReader(myRequestState.response.GetResponseStream());
this.allFileRows = reader.ReadToEnd();
}
catch (Exception e1)
{
this.monitor.PushToErrors("CJ - error in downloading the file - " , e1,true);
}
}
这是RequestState类:
public class RequestState
{
// This class stores the State of the request.
const int BUFFER_SIZE = 1024;
public StringBuilder requestData;
public byte[] BufferRead;
public HttpWebRequest request;
public HttpWebResponse response;
public Stream streamResponse;
public DateTime from;
public DateTime to;
public string prefix;
public string ext;
public RequestState()
{
BufferRead = new byte[BUFFER_SIZE];
requestData = new StringBuilder("");
request = null;
streamResponse = null;
}
}
这是请求调用的网址:
this._cj_url = "https://commission-detail.api.cj.com/v3/commissions?date-type=posting&start-date={0}&end-date={1}";
编辑:
由于某种原因,我在对服务实例启用了远程控制后,它得到了修复。 我真的很想知道我怎么会遇到这个问题...
一种想法是,当您在云中运行代码时,您正在它们的服务器上运行,这意味着您的日期可能全都不用了。 在您假设DateTime.Now
(或您正在做的任何事情)是您的时间之前,我已经看过了它,但实际上它是您在云中运行的VM的服务器时间。 可能是日期问题的原因是,我看到您正在将日期参数传递给URL,也许在云中运行时它们的格式设置错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.