Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 应用程序挂起在XMLString=client.DownloadString(rootURL+;basePolicyNumber);_C#_Http_Client_Downloadstring - Fatal编程技术网

C# 应用程序挂起在XMLString=client.DownloadString(rootURL+;basePolicyNumber);

C# 应用程序挂起在XMLString=client.DownloadString(rootURL+;basePolicyNumber);,c#,http,client,downloadstring,C#,Http,Client,Downloadstring,目录中有两张图片: IMG_经理_VAH007157100_d68807cb-8bd5-4ca8-861d-d878fa7e20b9.tiff IMG_经理_VAH007157200_121e8ae3-8e88-4775-be1e-a833e1c1eb51.tiff 我有一个按钮: private void btnUpload_Click(object sender, EventArgs e) { //check if all files in this

目录中有两张图片:

IMG_经理_VAH007157100_d68807cb-8bd5-4ca8-861d-d878fa7e20b9.tiff IMG_经理_VAH007157200_121e8ae3-8e88-4775-be1e-a833e1c1eb51.tiff

我有一个按钮:

private void btnUpload_Click(object sender, EventArgs e)
        {
            //check if all files in this folder are .tiff.

            finalImages = Directory.GetFiles(AppVars.FinalPolicyImagesDirectory);

            if (finalImages.Length == 0)
            {
                MessageBox.Show("There are no TIFF files to be uploaded. Please generate files first.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Web web = new Web();
                XML xml = new XML();

                //The first item in this foreach works fine. The second item gets hung.  
                foreach (string tiffFile in finalImages)
                {
                    PolicyNumber = Path.GetFileName(tiffFile).Substring(8, 12);

                    basePolicyNumber = PolicyNumber.Remove(PolicyNumber.Length - 2);
                    basePolicyNumber = basePolicyNumber + "00";

                    finalPolicyName = Path.GetFileName(tiffFile);

                //THIS IS WHERE I RUN INTO PROBLEMS......BUT ONLY WITH THE SECOND FILE IN THE FOREACH CLAUSE.
                    PolicyUUID = web.GetPolicyUUID(AppVars.pxCentralRootURL, basePolicyNumber);

                    if (!string.IsNullOrEmpty(PolicyUUID) == true)
                    {
                        ixLibraryPolicyBucketURL = AppVars.ixLibraryRootURL + "policy_" + PolicyUUID + "/objects/";

                        try
                        {
                            httpResponse = web.UploadFileToixLibrary(ixLibraryPolicyBucketURL, tiffFile);
                            xml.GeneratePayLoad(ixLibraryPolicyBucketURL + finalPolicyName + ".tiff", finalPolicyName);

                            //web.pxCentralPOST(ixLibraryPolicyBucketURL + "/IMG_MGR_37722779-7487-4d47-a669-ac33a61dceb2.tiff", AppVars.pxCentralRootURL + PolicyUUID, AppVars.pxCentralXMLPayloadFilePath);

                            MessageBox.Show(httpResponse);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }    
        } 
“foreach”子句中的第二项在此调用中挂起:

PolicyUUID=web.GetPolicyUUID(AppVars.pxCentralRootur,basePolicyNumber)

下面是该类/方法的代码:

public string GetPolicyUUID(string rootURL, string basePolicyNumber)
        {
            string PolicyUUID = "";

            using (WebClient client = new WebClient())
            {
                NetworkCredential credentials = new NetworkCredential();
                credentials.UserName = AppVars.Username;
                credentials.Password = AppVars.Password;
                client.Credentials = credentials;

                if (DoesPageExist(rootURL + basePolicyNumber) == true)
                {
                    try
                    {
                        XmlDocument doc = new XmlDocument();

                        string XMLString = "";

                        //the app stops working here. it just hangs, no errors or anything. IT WORKS THE FIRST TIME AROUND.
                        XMLString = client.DownloadString(rootURL + basePolicyNumber);

                        doc.LoadXml(XMLString);

                        var node = doc.DocumentElement.SelectSingleNode("//Identifier[@name='InsightPolicyId']");

                        if (node != null && node.Attributes["value"] != null)
                        {
                            var val = node.Attributes["value"].Value;
                            PolicyUUID = val.ToString();
                        }
                    }
                    catch (WebException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Page does not exist. This means that the policy number of the picture you're trying to upload does not exist in pxCentral. Please verify its name. The policy number in questoin is " + basePolicyNumber + ".", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return PolicyUUID;
        }

我不知道为什么在运行第二张图片的代码时,应用程序会挂起。有人能帮我一下吗?

使用Fiddler或类似工具检查网络上发生的情况。可能链接构造不正确

关于方法:

此方法在下载资源时阻止。要下载资源并在等待服务器响应时继续执行,请使用下载StringAsync方法之一


没有,哈哈!。如果我进行调试,我会逐行进行,然后在到达XMLString=client.DownloadString(rootURL+basePolicyNumber)之后;什么也没发生,黄色箭头消失了!我试图使用DownloadStringAsync,但它要求使用“System.URI”作为参数。我想用一根绳子。如何将字符串参数传递给DownloadStringAsync?