使用JavaScript的HTTP Post响应

时间:2015-01-14 20:59:51

标签: c# http-post

我已经尝试过几种不同的http发布方式,它总是以这篇帖子底部的脚本作为回应。我还在VBA中编写了一些代码,这些代码发布到相同的URL并且它应该响应。我的一位同事认为VBA代码有效,因为它使用的是启用了JS的IE引擎。我还需要在C#中做些什么才能让它发挥作用吗?

private static string TransformCmodReport(string ReportPath, string ModelPath)
{
    var request = (HttpWebRequest)WebRequest.Create("http://usflcmd1:80/RMSClient/RequestTypeAnalyze/AnalyzeRequest");

    string postData = "REQUEST_TYPE=E" +
        "&REPORT_HOST=usflcmd1" +
        "&REPORT_PATH=" + ReportPath +
        "&MODEL_PATHS=" + ModelPath +
        "&DEFAULT_VIEW=XLS_TABLE" +
        "&EXPORTTO=CSV";
    var data = Encoding.ASCII.GetBytes(postData);

    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.AllowAutoRedirect = true;
    request.UseDefaultCredentials = true;
    request.ContentLength = data.Length;

    using (var stream = request.GetRequestStream())
    {
        stream.Write(data, 0, data.Length);
    }

    var response = (HttpWebResponse)request.GetResponse();

    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

    return responseString;
}

回应......

   window.location =   '/ RMSClient /登录/ LoginIndex?RETURNURL =%2FRMSClient%2FExportMode%2FTryExport%3FappId%3D1abfc958-2694-42b9-a006-49ca5b786e44'   

编辑:这是正在运行的VBA代码

Public Function GetReportData(ReportPath As String, ModelPath As String) As String
    Dim strRequest As String
    Dim http As New MSXML2.ServerXMLHTTP60

    strRequest = "REQUEST_TYPE=E" & _
                 "&REPORT_HOST=usflcmd1" & _
                 "&REPORT_PATH=" & ReportPath & _
                 "&MODEL_PATHS=" & ModelPath & _
                 "&DEFAULT_VIEW=XLS_TABLE" & _
                 "&EXPORTTO=CSV"

    'Open the connection
    http.Open "POST", "http://usflcmd1:80/RMSClient/RequestTypeAnalyze/AnalyzeRequest", False


    http.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    http.setRequestHeader "Content-type", "application/x-www-form-urlencoded"

    'Send the payload
    http.send CStr(strRequest)

    'Get the response/error
    GetReportData = http.responseText

End Function

0 个答案:

没有答案