Click here to Skip to main content
15,123,367 members
Home / Discussions / Web Development
   

Web Development

 
QuestionModal Question Pin
MekaC24-Aug-21 11:40
MemberMekaC24-Aug-21 11:40 
Question.Net Framework Web API - Server Error Pin
Kevin Marois23-Aug-21 12:50
professionalKevin Marois23-Aug-21 12:50 
AnswerRe: .Net Framework Web API - Server Error Pin
Richard Deeming23-Aug-21 22:18
mveRichard Deeming23-Aug-21 22:18 
GeneralRe: .Net Framework Web API - Server Error Pin
Kevin Marois24-Aug-21 5:36
professionalKevin Marois24-Aug-21 5:36 
GeneralRe: .Net Framework Web API - Server Error Pin
Richard Deeming24-Aug-21 7:13
mveRichard Deeming24-Aug-21 7:13 
GeneralRe: .Net Framework Web API - Server Error Pin
Kevin Marois24-Aug-21 7:27
professionalKevin Marois24-Aug-21 7:27 
QuestionWebrequest is obselete what is the alternatieve Pin
Ger F. Versteeg27-Jul-21 0:45
MemberGer F. Versteeg27-Jul-21 0:45 
AnswerRe: Webrequest is obselete what is the alternatieve Pin
Richard Deeming28-Jul-21 0:57
mveRichard Deeming28-Jul-21 0:57 
For a start, you'll need to make your method async to use the HttpClient class. Which unfortunately means you'll need to make the calling method async, and so on - it's async all the way down.

At the basic level, your code would look something like this:
C#
public async Task<ToProgModel> ProgCsvAsync(Uri webSiteProg, ToProgModel prog, string complextProg)
{
    HttpClient client = new HttpClient();
    SetBasicAuthHeader(client.DefaultRequestHeaders, AuthorisatorProg, PasswordProg);

    using (HttpResponseMessage response = await client.GetAsync(webSiteProg))
    {
        if (!response.IsSuccessStatusCode)
        {
            prog.Ret = $"Http response EX: {response.StatusCode}";
            return null;
        }
        
        string progTextString = await response.Content.ReadAsStringAsync();
        ...
        return prog;
    }
}

public void SetBasicAuthHeader(HttpRequestHeaders headers, string userName, string userPassword)
{
    string authInfo = userName + ":" + userPassword;
    authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
    headers.Authorization = new AuthenticationHeaderValue("Basic", authInfo);
}
There are several improvements you can make to this - for example, using IHttpClientFactory[^] to manage the HttpClient instances.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Webrequest is obselete what is the alternatieve Pin
Ger F. Versteeg28-Jul-21 1:58
MemberGer F. Versteeg28-Jul-21 1:58 
GeneralRe: Webrequest is obselete what is the alternatieve Pin
Richard Deeming28-Jul-21 4:09
mveRichard Deeming28-Jul-21 4:09 
GeneralRe: Webrequest is obselete what is the alternatieve Pin
Ger F.28-Jul-21 5:24
MemberGer F.28-Jul-21 5:24 
QuestionWebsite Deployment Pin
Promise Sheggs21-Jul-21 11:32
MemberPromise Sheggs21-Jul-21 11:32 
QuestionHow to place text over an image using HTML/CSS? Pin
Alex Dunlop21-Jul-21 8:52
MemberAlex Dunlop21-Jul-21 8:52 
AnswerRe: How to place text over an image using HTML/CSS? Pin
Member 1529865622-Jul-21 22:43
MemberMember 1529865622-Jul-21 22:43 
GeneralRe: How to place text over an image using HTML/CSS? Pin
Alex Dunlop23-Jul-21 8:44
MemberAlex Dunlop23-Jul-21 8:44 
GeneralRe: How to place text over an image using HTML/CSS? Pin
Alex Dunlop24-Jul-21 5:21
MemberAlex Dunlop24-Jul-21 5:21 
QuestionWhat does an "Error 503 first byte timeout" mean? Pin
swampwiz1-Jul-21 20:15
Memberswampwiz1-Jul-21 20:15 
AnswerRe: What does an "Error 503 first byte timeout" mean? Pin
Richard MacCutchan1-Jul-21 22:02
mveRichard MacCutchan1-Jul-21 22:02 
QuestionHow Much the Budget should be for a website like OLA and UBER Pin
Ali Salman Jun14-Jun-21 2:52
MemberAli Salman Jun14-Jun-21 2:52 
AnswerRe: How Much the Budget should be for a website like OLA and UBER Pin
Member 1346058223-Jun-21 0:36
MemberMember 1346058223-Jun-21 0:36 
AnswerRe: How Much the Budget should be for a website like OLA and UBER Pin
SeeSharp214-Jul-21 11:41
MemberSeeSharp214-Jul-21 11:41 
QuestionImport Excel sheet into Gridview and SQL Pin
Michael Hinkle18-May-21 17:41
MemberMichael Hinkle18-May-21 17:41 
AnswerRe: Import Excel sheet into Gridview and SQL Pin
Richard MacCutchan18-May-21 22:15
mveRichard MacCutchan18-May-21 22:15 
GeneralRe: Import Excel sheet into Gridview and SQL Pin
Richard Deeming18-May-21 22:39
mveRichard Deeming18-May-21 22:39 
GeneralRe: Import Excel sheet into Gridview and SQL Pin
Richard MacCutchan18-May-21 23:01
mveRichard MacCutchan18-May-21 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.