I'm constructing a gather in C# from Twilio and for the URL attribute of gather constructor I need to pass a query parameter. For example "somepath?name=someName". However, i'm getting an exception saying that my urlString parameter is null. I tried to encode the "somepath?name=someName", but didn't work.
How can I pass query parameters for Twilio gather's URI?
I just urlencoded context data and added it to the path such as "somepath/somedata". The only time I really need to do that was a new call where I didn't already have a CallSid to reference in the backend.
I figured out how to do it. The following solution works:
var gather = new Gather(
new[] { Gather.InputEnum.Speech }.ToList(), new Uri($"{Url.ActionUri(nameof(MethodName), MyControllerName)}?name=some_name", UriKind.Relative), speechTimeout: "auto");
Related
I'm using the Google Vision API in C#. I want to set a quota on the number of calls I make on behalf of a user. The documentation says to use the quotaUser parameter in the request. However, I can't figure out where I can specify `quotaUser in the C# API.
https://cloud.google.com/apis/docs/capping-api-usage
I've looked at the generic API documentation here: https://cloud.google.com/apis/docs/capping-api-usage
This is the working code I have, which I'd like to modify to pass in a quotaUser value:
var cred = Credentials.CreateScoped(ImageAnnotatorClient.DefaultScopes);
var channel = new Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), cred.ToChannelCredentials());
var client = ImageAnnotatorClient.Create(channel);
var image = Image.FromBytes(bytes);
var annotations = Client.DetectDocumentText(image);
How can I modify this code to pass in a quotaUser parameter?
Am new to Elastic search and NEST, I am trying to get connected with my ES server through NEST. My ES Connection initialization looks like below.
ElasticClient client = null;
public void Connect()
{
var local = new Uri("http://192.168.40.95:9200/");
var settings = new ConnectionSettings(local).DisableDirectStreaming();
client = new ElasticClient(settings);
settings.DefaultIndex("gisgcc18q4");
ReadAllData();
}
public void ReadAllData()
{
var x= client.Search<dynamic>(s=> s.MatchAll());
}
The response is attached as image below,
I am Never getting any Hits, or data. Did i made any mistake in my connector, Also please suggest me good tutorials to convert JSOn ES query to NEST as well.
Looking at the Uri in the screenshot
POST /gisgcc18q4/object/_search?typed_keys=true
suggests that you're using a version older than 7, such as 5 or 6, where document types are used. In this case, the document type name "object" has been inferred from the dynamic type passed as the generic parameter argument, but I suspect that documents have not been indexed with a document type name of "object", but something else.
If the index "gisgcc18q4" only contains one type of document, you can use
var x = client.Search<dynamic>(s=> s.MatchAll().AllTypes());
Or you can pass the specific document type name to use
var x = client.Search<dynamic>(s=> s.MatchAll().Type("_doc"));
A good getting started tutorial for the client is the elasticsearch-net-example GitHub repository. It is a walkthrough in building out a ASP.NET Core web application to search Nuget packages.
Your connection looks fine, can you please validate the detailed summary under DebugInfrormation by clicking on it and get the row query and response.
After apply same query on Postman.
Please copy and paste below expression on quick watch window on the same line which is displayed in your screenshot.
((Elasticsearch.Net.ApiCallDetails)response.ApiCall).DebugInformation
You will get the detailed information, it will be helpful for you to investigate this issue.
I used Twilio's example code to successfully make a call - but I would like to instead pass in a string - as opposed to Twilio going to the URL to get the XML file to parse.
Does anyone know if it is possible?
A sample or at least getting me pointed in that direction would be appreciated too.
Thank you in advance!!
public class TwilRestCall
{
public void testCall_Send()
{
const string accountSid = "sdfsf...";
const string authToken = "fghfghf...7;
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("+15551212");
var from = new PhoneNumber("+15551213");
// Would prefer to pass in string instead of having it go to URL
var call = CallResource.Create(to, from, url: new Uri("https://handler.twilio.com/twiml/blahblah_Or_Use_Azure_Live_Or_Link_FromnGrokTesting"));
}
Twilio Developer Evangelist here.
The url parameter of the Create method is used to point Twilio to the specific TwiML that it will get and parse once the call connects successfully. We currently do not have a way to pass that TwiML string to Twilio from the method call.
However, you can setup an API of sorts that hosts an XML file (and this file would contain your TwiML string). Then you could use ngrok (if you're doing local development) to expose the URL of that file to Twilio. I'm not sure if this helps, but I hope it clears up any confusion. Let me know what you think.
I'm trying to perform some actions on a remote server using the XML-RPC .NET library and C#. I have no prior experience using this protocol but most examples seemed pretty straight forward. But the server I'm trying to communicate with seems to parse commands slightly different than most examples I've seen.
All calls are made using a 'perform_actions' function and it expects a list of action(s) along side with it as parameter. Fortunately there's a pretty decent documentation with some code samples included but these examples are done in Ruby/Perl with which I have no experience. I've tried translating these to C# with which I believe I'm on the right path but I'm consistently getting the error"Server returned a fault exception: [400] Invalid request: expected list of actions."
My current code
[XmlRpcUrl("https://DOMAIN/admin/rpc")]
public interface iFace : IXmlRpcProxy
{
[XmlRpcMethod("perform_actions")]
XmlRpcStruct[] perform_actions(XmlRpcStruct struc);
}
public void GetData()
{
XmlRpcStruct actions = new XmlRpcStruct();
actions.Add("name", "registrations.accounts.list");
iFace proxy = XmlRpcProxyGen.Create<iFace>();
proxy.Credentials = new NetworkCredential("USERNAME", "PASSWORD");
XmlRpcStruct[] response = proxy.perform_actions(actions);
}
And here is a Ruby example from the API documentation which I was trying to replicate which is functional
require 'xmlrpc/client'
url = 'https://user:passwd#qmanage.example.com/admin/rpc'
c = XMLRPC::Client.new_from_uri(url)
# Call the action to list the access groups.
ags = c.call('perform_actions', [{
'name' => 'network.accessgroups.list',
'args' => {}
}])
The server doesn't really seem to recognize the XmlRpcStruct I'm sending as the error seems to complain about not receiving a list of actions. (I receive the same error if I send no parameter). However if I change the XmlRpcStruct to a regular string array it will complain about expecting a struct instead so the data isn't ignored entirely.
Is anyone able to help me in the right direction with my problem or does anyone know why this error is returned?
Finally managed to figure out my dilemma. Seems I had to pass an array of XmlRpcStruct's rather than just singular XmlRpcStruct, the following solved my problem:
XmlRpcStruct[] actions = new XmlRpcStruct[1];
XmlRpcStruct action = new XmlRpcStruct();
action.Add("name", "registrations.accounts.list");
actions[0] = action;
I just passed actions as parameter to the perform_actions function.
I am trying to get a value from a Encoded URL in C#. So for example, I am trying to get "customerID" from:
http://<DOMAIN>/default.aspx%3FcustomerID%3D12345%26reference%3D2222
I tried the following:
string customerID = HttpUtility.UrlDecode(Request.QueryString["customerID"]);
But it comes back NULL. What is the proper way to get this value??
Thanks
Jay
string str = " http://DOMAIN/default.aspx%3FcustomerID%3D12345%26reference%3D2222";
var url = HttpUtility.UrlDecode(str);
var parameters = HttpUtility.ParseQueryString(new Uri(url).Query);
var id = parameters["customerID"];
your application should be encoding the ? and = signs. The Request variables are setup by iis usually before the information is handed off to the application handling the request. You need to send the should encode values but not the entire url. If your url looked like,
?customerID=1234 I imagine it would work, the problem is not with your code but with how the url is being constructed.