Properly changing HttpClient headers for different calls in C#? -


i'm writing program makes post , calls asynchronously. issue i'm running each post , have different headers/host parameters.

i have httpclient initialized outside main() class , inside main class have following,

client.defaultrequestheaders.add("host", "website1.com"); 

and get/post request want have website2 in host parameter,

client.defaultrequestheaders.add("host", "website2.com"); 

but collide , it's throwing error because exists. what's proper way approach this?

use sendasync instead of getasync or postasync

var request = new httprequestmessage(httpmethod.get, new uri("http://targeturi.com")); request.headers.host = "website2.com" var response = await client.sendasync(request); 

you can add many headers want request before sending it


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -