在服务器上发布ajax帖子时,如何修复错误500?

在服务器上发布ajax帖子时,如何修复错误500?,ajax,asp.net-mvc,http-post,Ajax,Asp.net Mvc,Http Post,我在MVC应用程序中通过ajax制作了一个httpPost,在本地没有任何错误。在服务器上运行相同的代码时,出现以下错误: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机未能响应[ip地址] 我尝试过通过谷歌找到的东西,但我尝试过的任何东西都没有解决我的问题,也没有改变我得到的错误 以下是我的cshtml中的ajax代码: function Test(dynamic1, dynamic2, dynamic3) { var webApiUri = &q

我在MVC应用程序中通过ajax制作了一个httpPost,在本地没有任何错误。在服务器上运行相同的代码时,出现以下错误:

连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机未能响应[ip地址]

我尝试过通过谷歌找到的东西,但我尝试过的任何东西都没有解决我的问题,也没有改变我得到的错误

以下是我的cshtml中的ajax代码:

function Test(dynamic1, dynamic2, dynamic3) {
    var webApiUri = "@Url.Action("Index", "Home")";
    var data = {
        someId: dynamic1,
        date: dynamic2,
        time: dynamic3,
        address: '',
        city: '',
        message: '',
        apiKey: ''
    };
    $.post(webApiUri, data)
        .done(function (pdfUrl) {
            $.fancybox.open({
                src: '/folder/' + pdfUrl,
                type: 'iframe'
                }
            });
        });
}
这是我的控制器代码:

public async Task<String> Index(PDFAPI api)
{
    using (var client = new HttpClient())
    {
        api.date = DateTime.Parse(api.date).ToString("yyyy-MM-dd");
        api.address = "10 ABC Avenue";
        api.city = "Pinkerton";
        api.message = "HelloWorld";
        api.Key = "p45sw3rd!";
        client.DefaultRequestHeaders.Add("Authorization", "Basic p00p#2");
        var response = await client.PostAsJsonAsync("https://child.example.com/images/pdf", api);
        var content = await response.Content.ReadAsAsync<ImageResponse>();
        var newFile = string.Empty;
        if (content.ErrorCode == "404")
        {
            newFile = $"noPic.jpg";
            System.IO.File.OpenRead(Server.MapPath($@"~/PDF/{newFile}"));
        }
        else
        {
            var date = DateTime.Parse(api.date).ToString("yyyy-MM-dd");
            var someId = api.SomeId; 
            newFile = $"{username}-{date}-{someId}.pdf";
            System.IO.File.WriteAllBytes(Server.MapPath($@"~/PDF/{newFile}"), Convert.FromBase64String(content.PDFString));
        }
        return $"{newFile}";
    }
}
公共异步任务索引(PDFAPI api) { 使用(var client=new HttpClient()) { api.date=DateTime.Parse(api.date.ToString)(“yyyy-MM-dd”); api.address=“ABC大道10号”; api.city=“平克顿”; api.message=“HelloWorld”; api.Key=“p45sw3rd!”; client.DefaultRequestHeaders.Add(“授权”、“基本p00p#2”); var response=wait client.PostAsJsonAsync(“https://child.example.com/images/pdf“,api); var content=wait response.content.ReadAsAsync(); var newFile=string.Empty; 如果(content.ErrorCode==“404”) { newFile=$“noPic.jpg”; System.IO.File.OpenRead(Server.MapPath($@“~/PDF/{newFile}”); } 其他的 { var date=DateTime.Parse(api.date).ToString(“yyyy-MM-dd”); var someId=api.someId; newFile=$“{username}-{date}-{someId}.pdf”; System.IO.File.writealBytes(Server.MapPath($@“~/PDF/{newFile}”)、Convert.FromBase64String(content.PDFString)); } 返回$“{newFile}”; } } 我哪里出了问题