How to fix "The remote name could not be resolved" - asp.net-web-api

I've created asp.net web-api , In the controller I try to call an external URL to send sms(the sms URL I get from the sms provider company )
When I try to call the controller I get this error
"The remote name could not be resolved"
This error only happened on the server ,On the localhost it's working fine
I am using Azure hosting
I tried to add some code to the webconfig
<defaultProxy enabled="true" useDefaultCredentials="true">
I also tried to call the sms URL in a different way
HttpClient client = new HttpClient();
response = client.GetAsync(urlParameters);
I've read some solutions about allowing access for the external link(SMS) on firewall and DNS of the server but it's already configured on azure server
Here is my code
string webAddress = "http://----------------";
string SomeData = System.Text.Encoding.Default.GetString((new
System.Net.WebClient()).DownloadData(webAddress));
I want my web api to send the sms without any error on the server side

Finally ,I solved the problem by replacing the SMS provider URL by their IP Address.
Here is an example of my solution :
Ex : http://123.123.123.123:12345/TEST/Para?i1=

Related

What is the request that whatsapp cloud api does to verify a webhook?

I'm able to verify the webhook using glitch from the getting started:
https://glitch.com/edit/?fbclid=IwAR2YTjZuGGM9Hi6T_v1eZh_nV6_HY3RYn_8lll4gY1REa_bJy6ZAuq6tkKQ#!/whatsapp-cloud-api-echo-bot
my local server (in a subdomain with https enabled) has the same behavior as glitch and show "WEBHOOK_VERIFIED" on the log for the request:
/webhook?hub.mode=subscribe&hub.verify_token=xpto123&hub.challenge=123
but when try to verify my local server the request from meta does not reach the server.
chrome showing that the connection to the server is secured
After more tests I found that my local server was been blocked by the ISP, understood it after test with another connection.
I made my own server and had tried ngrok and other programs to run it from local host with https redirect but whatsapp doesn't allow the use of those programs.
In the end, my error was that the URL HAS to end in /webhook or else, it won't even send the request. Then it'll send a GET request and you have to return the hub.challenge query param after making sure that the provided token from them is the one you set up. This is my code using NodeJS
if(req.query['hub.verify_token'] === process.env.VERIFY_TOKEN) return res.status(200).send(req.query['hub.challenge'])

Jersey client with multi domain uri

I am using Jersey Client API to talk to REST server.
Client is having problem in connecting to URL with multiple sub-domains.
EX : https://domain1.domain2.abc.com.
This throws 503 service unavailable.
i trusted all the certs and bypassed host name verification.
Even with HttpsUrlConnection API i get the same 503 error.
But when i hit the same URL with CURL that works fine.
I see the Client API works well with https://domain2.optum.com.
Is there any restriction for Jersey Client (HttpsUrlConnection)API with sub domain names in the URL?

Request failing when I try to send mail to Exchange Server using Exchange Web Services

My code to send mail
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("shiva#shiva.com","pwd");
service.setCredentials(credentials);
service.setUrl(new URI("C:/shiva/Services.asmx"));
EmailMessage msg = new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
msg.getToRecipients().add("shiva#shiva.com");
msg.send();
I'm getting following error when I ran above code
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Protocol C isn't supported for service request.
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74).
.
.
.
.
Caused by: microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException: Protocol C isn't supported for service request.
at microsoft.exchange.webservices.data.core.ExchangeServiceBase.prepareHttpWebRequestForUrl(ExchangeServiceBase.java:322).
.
.
.
Please help me.
The problem is that you don't point to the URI where your Exchange Web Services (EWS) instance is hosted. Instead your just pointing to the location in the file-system:
service.setUrl(new URI("C:/shiva/Services.asmx"));
So the URI-class tries to interpret C:/ as a protocol which won't work in this situation.
What you'll have to do is the following: Host your EWS-instance on a web server (usually Microsoft IIS in this case. I think you'll need a Windows Server with having set up the required server roles etc.). And let your code point to that URI instead:
service.setUrl(new URI("http://localhost:1234/someWhere/Services.asmx"));

Capture HTTPS request to nonexistent server with FiddlerCore

I am trying to send a response to an HTTPS request, using FiddlerCore.
I need things to work like this: I put some fake URL in browser, like https://my_url_that_doesnt_exist.com/, then I intercept this request with FiddlerCore and respond to it with my data. But I only see a CONNECT and the host URL. I know this is because of HTTPS and Fiddler being a proxy. But is there a way to get the real full URL and be able to respond to HTTPS request, using FiddlerCore?
Also I use this code to create a root certificate if it's missing:
if (!Fiddler.CertMaker.rootCertExists())
{
if (!Fiddler.CertMaker.createRootCert())
{
throw new Exception("Could not create a certificate.");
}
}
also, I use these startup settings:
FiddlerCoreStartupFlags fcsf = FiddlerCoreStartupFlags.Default | FiddlerCoreStartupFlags.DecryptSSL|FiddlerCoreStartupFlags.AllowRemoteClients;
and CONFIG.IgnoreServerCertErrors = true;
This HTTPS request is not visible in Fiddler itself. I mean when I try some non-existent URL to which I'd like my app to respond with some custom content. It's also HTTP, not HTTPS, and Fiddler itself contains the following in response:
[Fiddler] DNS Lookup for "my_url_that_doesnt_exist.com" failed. The requested name is valid, but no data of the requested type was found
But if I use some existing HTTPS URL, like google plus or anything like that, I can see the HTTPS and all the request details.
So the question follows: How can I intercept HTTPS request to a non-existent URL and serve my content instead?
I can provide any additional details if needed.
Also makecert.exe is in the same folder where all my binaries are.
The problem is that HTTPS traffic flows through a CONNECT tunnel, and by default that secure traffic won't be sent if creating the CONNECT tunnel to the target server doesn't first succeed. Of course, if that target server doesn't exist, you end up with a DNS error in creating the tunnel, so the secure requests are never sent.
The workaround is to tell Fiddler to tell the client that the CONNECT tunnel was created, without even trying to contact the server. Do so by adding this inside the BeforeRequest handler:
if (oSession.HTTPMethodIs("CONNECT"))
{
oSession.oFlags["x-replywithtunnel"] = "GenerateTunnel";
return;
}

How to Configure web service client endpoint url?

We have a situation, our interface partner is calling our web service dynamically by calling our WSDL and consume web methods by using the endpoint defined in the WSDL.
Here, the problem is - As we are using reverse proxy server, the actual web service is hosted in different content server and have URL rewrite rule configured in proxy server to redirect the request to real content server. Our interface partner is successfully consumed our WSDL by using the given reverse proxy URL, but the WSDL is having the real content server URL and our interface partner is not having access to it.
They can change the endpoint url in their proxy class and consume the web service via the reverse proxy URL; unfortunately, they are using some common framework to dynamically build the end point from the received WSDL. So our client could not consume our web service.
Is there any way to determine the client's endpoint url in web service? Thanks in advance.
open wsdl file in browser. save as on local system with .wsdl extension. in client code give url of local file instead of server address as given below.
url = new URL("file:/C:/apps/Services.wsdl");

Resources