|
Suppose your API takes a ID and then it returns a JSON response with that the ID in it.
Ex: Get: http:/example.com/id="12345";
responsse:
{
id: "12345"
}
Is it possible to validate 100s of different APIs and their responses if they all contain the same parameter and its value you passed in the response, this could be any datatype and any attribute and check if response contains that. but they all are different.. and make it generic??
|
|
|
|
|
Maybe you should give us some more context info for this problem.
Like course number and title, which homework exercise, and the hand in deadline.
You could identify the college / university as well.
|
|
|
|
|
was that suppose to be funny? I am here just trying to get some ideas and help
|
|
|
|
|
Member 14779968 wrote: was that suppose to be funny? What makes you think it was? Care to explain?
We are just here to help; but no guarantees we'll be any.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
OK, then:
What type of application are you building?
Those "100s of APIs", are they developed in-house? Do you have access to their source code?
Could you give us a clue to why and how the solution you are searching should be applied to literally hundreds of APIs - are you (or your employer) actually developing (implementations for) hundreds of APIs that should use the same validation?
In these hundreds of APIs, could you give some hint to what kind of datatypes and attributes you will find?
Would it be an option to return to your superior and say: "I am convinced that it is a poor idea to make one super-general validation function for every possible data type and attribute in several hundred APIs. I suggest that we don't do that!" ?
... Noone here believes that your problem statement comes from a real-world software developments project. It shines bright and clear that this is an exercize given at a college or other educational institution.
So be honest with it: The professor has given us this assignment, and I here is what I have written to return the attribute name ("id") and value ("12345"): [...]. But he wants it to valid for "any datatype" - I don't understand what he means typ that; it comes as a string from the URL. How can it come as some other datatype?"
That would be a valid question that might generate responses. But the way you have presented it, it sounds more like: "I am too busy to do this homework assignment right now, so could someone please provide something for me to hand in?"
If you really are as totally blank as it seems, tell us. Indicate whichever pieces you have understood, if ever so small, and we could try to work it out from there. But be warned that you can only expect to get help to understand things enough to do the homework yourself. You won't get help so that you don't have to do it yourself.
|
|
|
|
|
Message Closed
modified 19-May-20 20:40pm.
|
|
|
|
|
Member 14779968 wrote: It is a real time enterprise application. On an OS that isn't realtime? Do explain that magic, or ask your money back.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks for help.. I will ask for my money back
|
|
|
|
|
|
Member 7989122 wrote: The professor has given us this assignment Find a decent one.
He's the teacher, so I refuse to explain. He's paid, not me.
Anything else you desire?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
You're welcome, of course.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
This was exactly what I needed. Thank you
|
|
|
|
|
Member 14779968 wrote: Is it possible to validate 100s of different APIs and their responses if they all contain the same parameter and its value you passed in the response, this could be any datatype and any attribute and check if response contains that. No.
Member 14779968 wrote: but they all are different.. and make it generic?? They'd have to provide additional info; nothing you can do to make it generic.
You can't be sure, unless they give you a validation method. (Not to be confused with a programming method).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
The "id" is a "key", the "12345" is a value. Which is the equivalent of a dictionary entry in a "dictionary" collection. In this case, it would be of generic type Dictionaty<string,string> which can be used to valid any "attribute / value" pair. You may need a separate dictionary for each API; a dictionary of dictionaries: Dictionary<string,dictionary<string,string>>. Duplicate API dictionaries are simply references to other dictionaries.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
how to add picture into mysql using datagridview
|
|
|
|
|
Probably by writing some code.
|
|
|
|
|
A datagridview is a component that displays things; it doesn't add things to a database. There's quite a lot of examples of saving and retrieving pictures from databases. What have you tried?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm using the following code to download a webpage:
public static GenericStatusType LoadHttpPageWithBasicAuthentication(string url, string username, string password)
{
GenericStatusType status = new GenericStatusType(GenericStatusCode.OK, null, "", "");
try
{
Uri myUri = new Uri(url);
WebRequest myWebRequest = HttpWebRequest.Create(myUri);
HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;
NetworkCredential myNetworkCredential = new NetworkCredential(username, password);
CredentialCache myCredentialCache = new CredentialCache();
myCredentialCache.Add(myUri, "Basic", myNetworkCredential);
myHttpWebRequest.PreAuthenticate = true;
myHttpWebRequest.Credentials = myCredentialCache;
WebResponse myWebResponse = null;
try
{
myWebResponse = myWebRequest.GetResponse();
}
catch (WebException e)
{
status.errorHeading = "Error Reading Web Page";
status.errorMsg = "A WebException occurred while trying to read from the following URL: " + url + ". Technical information: " + e.Message;
status.statusCode = GenericStatusCode.ERROR;
if (myWebResponse != null)
{
myWebResponse.Close();
}
return status;
}
Stream responseStream = myWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
string pageContent = myStreamReader.ReadToEnd();
responseStream.Close();
myWebResponse.Close();
status.value = pageContent;
}
catch (Exception e)
{
status.errorHeading = "Error Reading Web Page";
status.errorMsg = "An error occurred while trying to read from the following URL: " + url + ". Technical information: " + e.Message;
status.statusCode = GenericStatusCode.ERROR;
}
return status;
}
To my surprise, the string this method returns is different from what I get in Chrome if I do a regular "Save As" from a link to the particular webpage. I can see that when I download from within C#, I get an exception:
<span class="warning">Object reference not set to an instance of an object.. System.NullReferenceException: Object reference not set to an instance of an object In the html-file that I download through "Save As" the corresponding lines look like this:
<div class="ts-folder-diaginfo"></div><div class="ui grey attached inverted mini menu"><a class="item" How can I solve this i.e. get the same result from calling LoadHttpPageWithBasicAuthentication as downloading in Chrome using "Save As"?
|
|
|
|
|
Which line is the error on, and which variable? You need to know which reference is null in order to diagnose and correct it.
|
|
|
|
|
The exception is thrown at ASP.ts_feature_folder_exe_aspx.FolderViewRender(StringBuilder response, Column column, FieldWriter writer) inside folder.exe.aspx:line 414, which I do not have the source code for.
|
|
|
|
|
The stack trace should tell which line of your code was the place that led to the error.
|
|
|
|
|
Even if I would stack trace debug what's happening inside folder.exe.aspx:line 414 it would be of little help because I'm not the owner nor the webmaster of the webpage I'm trying to download. I just need to make my C# code act a little more like a genuine browser, because a genuine browser does not get this exception when performing "Save As".
|
|
|
|
|
The following seems to work fine, but there is so much source code in Chromium, I really hope there is an easier way:
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
{
if (e.Frame.IsMain)
{
chromiumWebBrowser.ViewSource();
chromiumWebBrowser.GetSourceAsync().ContinueWith(taskHtml =>
{
string html = taskHtml.Result;
File.WriteAllText("Downloaded from within Chromium.html", html);
});
}
}
|
|
|
|
|
Is this an error being displayed by the website you're requesting, rather than an exception thrown from your code?
Perhaps the server-side code depends on a header which you're not sending - for example, the user-agent[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|