|
What exactly are you trying to create? Perhaps the WebBrowser control isn't the ideal solution for this, but that depends on what you're trying to do. Kristian Sixhoej
"You can always become better." - Tiger Woods
|
|
|
|
|
Getting html code of a topic in a vbulletin forum.
If you're not logged in, you're not allowed to view the topic.
I can't log in with the response class.
This was my try:
private string login(string url, string username, string password)
{
string values = "vb_login_username={0}&vb_login_password={1}";
values += "&securitytoken=guest&cookieuser=checked&do=login";
values = string.Format(values, username, password);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = values.Length;
req.Timeout = 10000;
CookieContainer a = new CookieContainer();
req.CookieContainer = a;
System.Net.ServicePointManager.Expect100Continue = false;
using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
{ writer.Write(values, 0, values.Length); }
this.response = (HttpWebResponse)req.GetResponse();
StringBuilder output = new StringBuilder();
foreach (var cookie in response.Cookies)
{
output.Append(cookie.ToString());
output.Append(";");
}
return output.ToString();
}
</pre>
|
|
|
|
|
I don't know why your login request doesn't work, but another approach to the problem could be:
1. Navigate to the URL using the WebBrowser control.
2. If a login form is displayed, use HtmlDocument to fill in the values (username + password) and "click" the Login button. Depending on how the site is coded, the browser should automatically navigate to the requested forum topic.
3. Grab the HTML by using the DocumentStream property.
Although this definitely isn't the most ideal solution if you have to "visit" several sites. WebRequest is probably the way to go if that's the case.
Have you got any idea as to why your login request fails? Does the site display an error message? Kristian Sixhoej
"You can always become better." - Tiger Woods
|
|
|
|
|
Im already filling the form's manually in the webbrowser control.
My idea why the login fails is because of the 'salt' it adds after the password.
And it gets the salt from the DB.
If i could fill in the forms programmatically with webresponse and request, would be great.
This way, i dont have to load anything, which takes a lot of time.
|
|
|
|
|
Hi,
This is my code.
I'm a newbie to c# and I have been working on this for a few days.
{
readText = File.ReadAllText("C:\\PIn.txt");
string [] split = readText.Split(new Char [] {' '});
int splitCounter = 0;
foreach (string s in split)
{
splitCounter++;
if (splitCounter == 1)
bn1 = double.Parse(s);
if (splitCounter == 2)
bn2 = double.Parse(s);
if (splitCounter == 3)
bn3 = double.Parse(s);
if (splitCounter == 4)
bn4 = double.Parse(s);
}
Print("Pn: " + pn1 + " " + pn2 + " " + pn3 + " " + pn4);
As you can see I've used Print to make sure it is working but I am having a huge amount of trouble moving forward...please help. It's an important step for me.
Regards,
suprsnipes
|
|
|
|
|
Yes, ok, it's some code.
What is the problem - apart from "it doesn't find the nearest number above in comparison to another" which is a bit obvious, given there is no comparison in there...You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Can you explain what are you trying to do a little better ...
|
|
|
|
|
A couple of *gentle* hints, when posting to boards such as this.
1. Say what is wrong in the body of the question, if it is in the title it will get missed.
2. suprsnipes wrote: It's an important step for me. Saying this is likely to cause a flamewar (look at the posting guidance at the top of the board).
OK I don't fully undstand what the requirement is. Is
a) find the two items (or their position/index?) in the list adjecent to eachother that are closest in value where the second is higher than the first?
b) find the two items (or their position/index?) accross the whole list that are closest in value where the second is higher than the first?
An example would be helpful.
As a first pointer, you will need to keep the index of the closest two and update it if you find a closer pair inside the loop you have.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
I don't understand what your problem is with this. You had the code two days ago, I tested it and confirmed that it provided the result you wanted. And yet you keep coming up with a different (and ridiculous) algorithm and asking why it doesn't work.
May I suggest you stop writing code and work this out as a mathematical problem. Then write down the steps to solve it using simple mathematics. Then, and only then, convert your steps into code.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
For your information the code DIDN'T work. If it did I wouldn't be asking for help still...
|
|
|
|
|
Do you want to
Print("Pn: " + pn1 + " " + pn2 + " " + pn3 + " " + pn4);
or
Print("Pn: " + bn1 + " " + bn2 + " " + bn3 + " " + bn4);
?
|
|
|
|
|
I was using to Print to help me see what the code is doing and if I am on the right track...
Print("Pn: " + pn1 + " " + pn2 + " " + pn3 + " " + pn4);
The text document has numbers stored in it that I want to use in another piece of code which is already prepared but I am having a huge amount of trouble trying to get the number from the data set that I need.
|
|
|
|
|
I think what KenKen Wong was saying is: Your code will either not compile or not work as you expect, because you are putting information into bn1..bn4, and printing from pn1..pn4.
suprsnipes wrote:
if (splitCounter == 1)
bn1 = double.Parse(s);
if (splitCounter == 2)
bn2 = double.Parse(s);
if (splitCounter == 3)
bn3 = double.Parse(s);
if (splitCounter == 4)
bn4 = double.Parse(s);
}
Print("Pn: " + pn1 + " " + pn2 + " " + pn3 + " " + pn4);
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
suprsnipes wrote: For your information the code DIDN'T work.
So I lied! Good luck, you'll need it.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Thanks for the reply...
I'm not here to upset anyone just trying to get some help, coding might come easy to some, especially those that have been at it for years (I've been using C# for about 2 weeks), perhaps I should have said "the code didn't do what I required".
I use Print so that I can see the output and for some reason the suggested code was rounding down...I don't know why that is...so I placed what I had on the message board in hope that another member would be kind enough to give me some assistance...
My intention was not to offend anyone, surely you guys remember what it was like starting out?
suprsnipes
|
|
|
|
|
suprsnipes wrote: For your information the code DIDN'T work. If it did I wouldn't be asking for help still...
Perhaps it was this that raised the ire. The is a whole ettiqute involved with bulletin boards, and you've broken a few of them (e.g. reposting). Read the guidance at the top of the page. You also need to remeber that the regulars here frequently deal with students whose attitude is "I can't do my homework so here is the the question I've been set" normally finished with "This is urgent snd codez plz". I don't think your OP was like that, but we're all a bit jaded in here, and some people reuse to help students at all as they should be working this stuff out for themselves.
suprsnipes wrote: surely you guys remember what it was like starting out?
Yep. But the problem is you posted code that wasn't even close to to achieving what is needed (for examplethere is no comparison at all of the values ) and you haven't properly explained what you want, and (because the code isn't close) what is going wrong.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
suprsnipes wrote: perhaps I should have said "the code didn't do what I required".
This is where I am confused. You said you wanted to select the smallest integer greater than a certain floating point value which was rounded up. When I ran the code it worked fine and produced the correct result. You did not show the results you had received so there was no way of knowing what was different with your test.
suprsnipes wrote: My intention was not to offend anyone, surely you guys remember what it was like starting out?
Well CodeProject did not exist for one thing; I had a pencil, a coding pad, and a reference manual to help me - and hours of testing.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Ok, thanks for your reply Richard, let me convey my apologies.
This is my input, which is being read
4843
4811
4792
The floating value is 4820.
The result that I am getting is 4811.
The result that I am after is 4843, which is the next value up from 4820.
I have posted the code below;
int roundedValue;
int temp, result = 0;
int? diff = int.MaxValue;
readText = File.ReadAllText("C:\\PIn.txt");
string [] split = readText.Split(new Char [] {' '});
foreach (string s in split)
{
count++;
temp = int.Parse(s);
levels[count] = temp;
int roundedValue = (int)Close[0];
if (temp > roundedValue)
{
if (diff == 0)
diff = roundedValue;
if ((temp - roundedValue) < diff)
{
result = temp;
diff = temp - roundedValue;
}
}
}
Print("Result: " + result);
|
|
|
|
|
I just copied and pasted the above code into my C# compiler (twice to be sure) and it gives the correct result 4843! I cannot see why you should not get the same result, unless there is something external to this piece of code that is the problem. Check your input data, and try also stepping through your program with the debugger. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
You could cheat a little and use a list and it's sort method to help. Create the base list, add your value, sort it, get the index of your value and increment to get the next number up. Not very mathmatical or elegant (and probably inefficient) but it works.
class Program
{
static void Main(string[] args)
{
List<string> inputFromFile = new List<string>(3) {
"4843", "4811", "4792" };
int value = (int)4820f;
List<int> list = inputFromFile.ConvertAll(
new Converter<string, int>(StringToInt));
list.Add(value);
list.Sort();
int index = list.IndexOf(value);
if (index < (list.Count - 1))
Console.WriteLine(list[index + 1]);
else
Console.WriteLine(value);
Console.ReadKey();
}
private static int StringToInt(string text)
{
int result;
int.TryParse(text, out result);
return result;
}
} Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello
I'm a newbie with WebService creation
For now, everyhing works fine, my Service run on a server and my Client can use it
Now I need to add autentification to the service ...
How can I do that simply on the server site ?
It does'nt need to be very secure, I just want to understand how to do it
I have an example of another service that I'm using as a client
I just have to assign a NetworkCredential to the service's client instance to be able to use it
How can I achieve that on the server side
Thanks a lot for any help
|
|
|
|
|
Consider this example that works:
List<String> list = new List<string>(){"1","2","a","b"};
list = list.FindAll(delegate(String s)
{
if (s != "a")
{ return false; }
return true;
});
I can't understand why we can't do this :
List<T> list = (from c in oq select c).ToList();
list = list.FindAll(delegate(T o)
{
if (o.GetType().GetProperty("PropertyName").GetValue(o,null).ToString() != company)
{ return false; }
return true;
});
The 'propertyName' is a property that exists in the objects naturally.
This compiles fine but throws an object null reference exception...
Thank you for time...
|
|
|
|
|
The second code is very convoluted, I don't know why you are using reflection to get the property type.
List<T> list = (from c in oq select c).ToList();
list = list.FindAll(o => o.GetType().GetProperty("PropertyName").GetValue(o,null).ToString() == company));
is cleaner, but you can do the find all operation as where clause in the select. The problem you are currently getting is either because T doesn't have a propertyname (and if it does, why are you getting it by refelection?) or the property istelf has a null value.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Keith Barrow wrote: The problem you are currently getting is either because T doesn't have a propertyname (and if it does, why are you getting it by refelection?) or the property istelf has a null value.
That seems impossible because T has always got 'propertName' property and the value is never null because it's part of a primary key.
Keith Barrow wrote: you can do the find all operation as where clause in the select.
Maybe I didn't show enough code to make clear why I can't do the 'FindAll' in the 'Where' clause ...
var oq = (ObjectQuery<T>)(p.GetValue(EntityObject, null));
List<T> list = (from c in oq select c).ToList();
The type of the ObjectQuery is only known in runtime because I get a specific ObjectQuery thru reflection in runtime.
so
from c in oq select c where c.'no properties here' select c
...
|
|
|
|
|
Ok so it was the 'propertyName' that was incorrect, my mistake, sorry !
All is well and thank you for your input.
|
|
|
|