|
|
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
|
|
|
|
|
My code (the source code I included in my first post) works just fine (in the sense that it doesn't throw any exceptions), it returns a string with html as expected. The problem is the html itself, when I look at it inside Notepad then I see the System.NullReferenceException.
modified 18-May-20 7:39am.
|
|
|
|
|
So as I said, the server-side code is depending on a header that you're not sending with your C# code. The most likely culprit would be the user-agent.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Using the example code posted on the web page you linked to in your post, I was able to modify my code to the following:
public static GenericStatusType LoadHttpPageWithBasicAuthentication(string url, string username, string password)
{
GenericStatusType status = new GenericStatusType(GenericStatusCode.OK, null, "", "");
try
{
Uri myUri = new Uri(url);
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
myHttpWebRequest.UserAgent = ".NET Framework Test Client";
NetworkCredential myNetworkCredential = new NetworkCredential(username, password);
CredentialCache myCredentialCache = new CredentialCache();
myCredentialCache.Add(myUri, "Basic", myNetworkCredential);
myHttpWebRequest.PreAuthenticate = true;
myHttpWebRequest.Credentials = myCredentialCache;
HttpWebResponse myWebResponse = null;
try
{
myWebResponse = (HttpWebResponse)myHttpWebRequest.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;
}
As far as I can tell, this works great! For some reason, some values get changed (for example, ;_hide=;title;" id="x23866"> becomes ;_hide=;title;" id="x1295">), but that doesn't matter in my use case. Thanks for solving this!
|
|
|
|
|
The HTML code one gets often depends on the device the client uses (e.g. large desktop vs small mobile phone), therefore setting a reasonable useragent is pretty important, as Richard already told you.
Example: my desktop Windows10/Chrome browser uses this user-agent (a single rather long line of text):
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
|
|
|
|
|
Sometimes, when you have an exception on your code, that is catched and rethrown and that you press F5 (continue) the debugger will stop stop obstinately several times in a row in the same spot (I found that more prevalent in Web application) and you have to press F5 F5 F5.... but not too many times because, sometimes, the 8th or 9th time is in another relevant user method...
Is there a way to have the debugger stop on all exception, but skip some method altogether?!
I tried to decorate my relevant method with
[System.Diagnostics.DebuggerHidden]
[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerNonUserCode]
[System.Diagnostics.DebuggerStepperBoundary]
The closest I was to something was with DebuggerHidden , but it still stops like 8 or 9 times on my method (it's an ExceptionFilter ), just not select it...
modified 17-May-20 20:41pm.
|
|
|
|
|
When I start a new Windows Forms project in Visual Studio it always places the form at the upper left of the screen which seems stupid to me to put it there.
I'm looking for a way to move it to center screen.
As far as I know adjusting the Properties only affects run-time position of the form.
|
|
|
|
|
This is not a programming issue. You need to talk to Microsoft, it's their product.
|
|
|
|
|
I had to check this out, and I see the same thing.
But to me it seems quite natural. When I create a new text file, I start writing in the upper left hand corner, too.
All sorts of boes and forms, frames and whatever to be filled in, I feel it natural to fill left to rigth, top to bottom. If I want to drag a box larger, I alway drag the lower right corner (so the old contents stays in the same positions, unless it is flowing, of course.
Personal taste varies. But I am starting to ask myself why the window is centered when you work with a WPF app. I think upper left would be better.
|
|
|
|
|
Were you looking for the StartPosition property of your form? You can set that to "CenterScreen".
|
|
|
|
|
That only affects what your form looks like when you're at run-time. I was wondering if I can get the form positioned closer to the center of the screen at design-time, but I don't think that can be changed.
|
|
|
|