Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
63 views
in Technique[技术] by (71.8m points)

c# - Why am I not getting anything from my webrequest? What am I supposed to look for?

First of all I am new to C#. I am writing a WPF program in Visual Studio 2019. In my project I have multiple web requests and whilst testing how they work the functionality was minimal: only the web requests were made and they were working fine until now. The login authorization request still works.

This is my webrequest.

using (var client = new WebClientEx())
{
    client.BaseAddress = serverurl.serviceurl;
    client.UseDefaultCredentials = true;

    string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(excelvertibas.username + ":" + excelvertibas.password));
    
    client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    client.Timeout = 90000;
                    
    byte[] postArray = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(domObjectVariables));
    client.Headers.Add("Content-Type", "application/json");//----------------
    client.Encoding = Encoding.UTF8;
    byte[] responseArray = client.UploadData(serverurl.serviceurl + "StartAddDigitalObject", "post", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(domObjectVariables)));  //----------------------------
    domMetadataAddResponse = JsonConvert.DeserializeObject<StartAddDigitalObjectResponse>(Encoding.UTF8.GetString(responseArray));
}

The base address works, I tested it manually through Postman.

Username and password are also correct which I have tested.

Post array is also passing information which is needed, and I have checked it whilst adding breakpoints.

My question is why could this be not working anymore and what should I look for?

fyi this is the line of code where is should be getting information back into the response array but for some reason it stays null.

byte[] responseArray = client.UploadData(serverurl.serviceurl + "StartAddDigitalObject", "post", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(domObjectVariables)));  

After this the program breaks because the response array contains nothing when I try to pass it further.

question from:https://stackoverflow.com/questions/65847738/why-am-i-not-getting-anything-from-my-webrequest-what-am-i-supposed-to-look-for

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...