|
Goal: Use VB application to submit multiple values to a webform
I have the data I want to send to the xxxxx.com website collected from fiddler2. I used fiddler 2 to post and it works. I would like to use this information like fiddler2 is using to execute the submit button.
fiddle information:
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-silverlight-2-b2, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://xxxxxxxxxxxxxxxxxxxxxxxxx.com/
Accept-Language: en-us
Content-Type: multipart/form-data; boundary=---------------------------7d93aa14e06c8
UA-CPU: x86
Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; MS-RTC LM 8)
Pragma: no-cache
Content-Length: 20603
Host: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com
Cookie: HPF_Group=1; sauid=U3344282; JSESSIONID=(J2EE200)ID19737905End; SAPWP_active=1; sap-ssolist=O3I9Q1JNUFJEQVAwQl9DTVBf%3D; sasid=S99024; sa_uvc=U3396744282
and the following as a sample:
-----------------------------7d93aa14e06c8
Content-Disposition: form-data; name="__EVENTTARGET"
-----------------------------7d93aa14e06c8
Content-Disposition: form-data; name="__EVENTARGUMENT"
-----------------------------7d93aa14e06c8
Content-Disposition: form-data; name="__LASTFOCUS"
Dim url As String = "http://xxxxxxxx.com/"
Dim oWeb As New System.Net.WebClient()
oWeb.Headers.Add(HttpRequestHeader.Accept, "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-silverlight-2-b2, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*")
oWeb.Headers.Add(HttpRequestHeader.Referer, "http://xxxxxxx.com/")
oWeb.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us")
oWeb.Headers.Add(HttpRequestHeader.ContentType, "multipart/form-data; boundary=---------------------------7d93aa14e06c8")
oWeb.Headers.Add(HttpRequestHeader.Connection, "Keep-Alive")
oWeb.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; MS-RTC LM 8)")
oWeb.Headers.Add(HttpRequestHeader.Pragma, "no-Cache")
oWeb.Headers.Add(HttpRequestHeader.ContentLength, "30603")
oWeb.Headers.Add(HttpRequestHeader.Host, "http://xxxxxxx.com/")
oWeb.Headers.Add(HttpRequestHeader.Cookie, "HPF_Group=1; sauid=U3 712!56hE mIQ%3D%3D; sasid=S593 99024; sa_uvc=U339 05744282")
Try
oWeb.UploadString(url, "POST", TextBox1.ToString)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
I also tried the following way. Got a little sloppy after a while. This is how I last left it before my head started hurting
Dim objEncoding As New System.Text.UTF8Encoding
Dim objStream As System.IO.Stream
Dim objHTTPRequest As HttpWebRequest
Dim sbPostData As New System.Text.StringBuilder
Dim objStreamReader As System.IO.Stream
Dim strResult As String
'set request properties
objHTTPRequest = System.Net.WebRequest.Create("http://xxxxxxxxxxxxxxx.com/")
objHTTPRequest.AllowAutoRedirect = True
objHTTPRequest.Accept = "*/*"
objHTTPRequest.KeepAlive = False
objHTTPRequest.Timeout = 30000
objHTTPRequest.Method = "POST"
objHTTPRequest.ContentType = "multipart/form-data; boundary=7d93aa14e06c8"
objHTTPRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-silverlight-2-b2, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*"
objHTTPRequest.Referer = "http://xxxxxxxxxxxxxxxxx.com/"
' objHTTPRequest.a.Accept-Language = "en-us")
objHTTPRequest.ContentType = "multipart/form-data; boundary=---------------------------7d93aa14e06c8"
' objHTTPRequest.u.UA-CPU = "x86")
'objHTTPRequest.Connection = "Keep-Alive"
objHTTPRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; MS-RTC LM 8)"
' objHTTPRequest.Pragma = "no-Cache")
objHTTPRequest.ContentLength = "30603"
' objHTTPRequest.Host = "http://xxxxxxxxxxxxxxxx.com/")
' objHTTPRequest.Cookie = "HPF_Group=1; sauid=U33961282; JSESSIONID=(J2EE117803200)ID1972977451DB11724142932769437905End; SAPWP_active=1; sap-ssolist=!56hEH4wnxXmIQ%3D%3D; sasid=S5939024; sa_uvc=U3344282")
'convert our other post data into a byte array
Dim bytPostContents As Byte() = objEncoding.GetBytes(boundry().ToString)
'get our stream and post our data
objStream = objHTTPRequest.GetRequestStream()
'close our stream
' objStream.Close()
'get the response from the server
Dim objHTTPResponse As HttpWebResponse = CType(objHTTPRequest.GetResponse(), HttpWebResponse)
objStreamReader = objHTTPResponse.GetResponseStream()
'final result from server is returned to strResult
Dim objStreamResult As New System.IO.StreamReader(objStreamReader)
strResult = objStreamResult.ReadToEnd
'close our objects
objStreamReader.Close()
objStreamResult.Close()
End Sub
|
|
|
|
|
I'm searching for a replace-funktion for controlselections.
I know, it is possible if you first delete and then add an new control but the control has to have the same index(=postion on the form) than before.
And I found no "addat"-funktion
Has someone an idea?
|
|
|
|
|
That depends on the collection you're using. The Controls collection in the Form class has no such facility, and frankly, if your design relies on the order the controls have been added to it, you need to rethink your design. You shouldn't be using the index in the collection to find controls. You should be positively identifying controls using things such as their name or some other ID you put in the control's Tag property.
|
|
|
|
|
Create the new control in your code, then find the old control by looping through your form's control collection and checking the type of the controls, or the name of each control. When you find the one you're looking for, convert it (using Ctype) to the new one. This way the index doesn't change.
Here's an example of using Ctype. I use this method in a tabbed text editor with an extended RichTextBox class. The RTBs are contained in a collection ("allFiles") of type "myRTF" (the extended RTB). All editing is done with an in-memory RTB named "rtf". When the tab control's selected index changes, the following code gets the tab control's new SelectedIndex and finds the correct item in the collection:
index = tabs.SelectedIndex
rtf = CType(allFiles(index), myRTF)
The in-memory RTB ("rtf") is converted to the proper member of the collection. You can use a similar method to "insert" your new control without affecting the indexes in the control collection.
|
|
|
|
|
I have this application from several years ago that I am modifying.
I created a new form where I have an Xceed grid tied to a DataSet-DataAdapter. When the Add button (or a blank area on the grid) is clicked, it creates a new row. The user types information there and clicks "Save". Or the user edits an existing row and clicks "Save".
The data adapter calls the Update() method that invokes the corresponding SQL Insert/Update/Delete commands. It works fine.
But I have a link table where I want to Insert when a new row is saved in the previous table mentioned above. How do I know a new row has been created and "Save" button is clicked or an existing row is edited and the "Save" button is clicked?
I need some help please.
Thanks.
|
|
|
|
|
I got it done, thanks if you read it.
|
|
|
|
|
Hi,
With my datagridview I have column for datetime. I used the following for format.
Dim secidexp As New DataGridViewTextBoxColumn
With secidexp
.MaxInputLength = 10
.DataPropertyName = "sec_id_expiry"
.HeaderText = "ID EXPIRY DATE"
.DefaultCellStyle.Format = "dd/MM/yyyy"
End With
But the problem is it's getting input like MM/dd/yyyy and after pressing enter it's changing to dd/mm/yyyy style.
So is it possible to get input like "dd/MM/yyyy"
PS: This Problem occours only in Editing the rows & for New Rows.
Thanks ...
|
|
|
|
|
This is probably dependent on the culture info of the computer. Look into setting the culture info for the datagridview. I'm only guessing as I generally don't allow data entry into a grid control, I force the user to a details dialog for data manipulation where you have much finer control.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Basically, my goal is to get a multiline TextBox or a RichTextBox to resize the font of its text until all of the text can be seen. The following code works to make the text fit on one line, but I am not sure how to change it to work for multiple lines.
Public Shared Function BestFontSize(ByVal g As Graphics, _
ByVal z As Size, ByVal f As Font, ByVal s As String) As Single
Dim p As SizeF
p = g.MeasureString(s, f)
Dim hratio As Double = z.Height / p.Height
Dim wratio As Double = z.Width / p.Width
Dim ratio As Double = Math.Min(hratio, wratio)
System.Console.WriteLine(f.Size * ratio)
Return f.Size * ratio
End Function
Private Sub TextBox1_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text <> "" Then TextBox1.Font = New Font(TextBox1.Font.FontFamily, _
BestFontSize(TextBox1.CreateGraphics, TextBox1.Size, TextBox1.Font, TextBox1.Text))
End Sub
Is there a way to determine which characters are actually visible on screen? Any ideas on a better way to do this?
|
|
|
|
|
I've done soemthing like this before. Basically, there's no function that will do this for you and no way to tell what has been drawn and what hasn't. What I did was use MeasureString with a starting font size, see if it fit in an available space, and if not, reduce the font size and measure it again. Keep going until you reach either a minimum acceptable font size or the drawn text finally fits.
Warning! This method can be slow and reduce your app's performance.
In a second version of the app I did, I ended up drawing the text to a bitmap in a fixed-size, but larger, font, then drawing that bitmap to the screen scaled to the proper size. The final drawn text quality suffered a little bit from the scaling, but the performance was much better.
|
|
|
|
|
Hi,
this is what I would try:
0.
choose fontsize fs1=10;
1.
use Graphics.MeasureString() with some font (fontsize fs1), the right width, and let it compute the height that would take. Make sure to give it all parameters equal to what you will use in the TextBox eventually.
2.
calculate a new fontsize as fs1 = fs1 * 0.9 * textboxHeight/measureStringHeight; (use floating-point!)
3.
since with a different font size word wrapping will be different too, iterate steps 1 and 2 say three times. (The 0.9 factor above is there to reduce the likelihood final text does overflow just a bit)
|
|
|
|
|
i am developing one eform designer project..the main object of this project is there a form in this controls are drag and drop.moving and deleting and editing the properties ..it's like a our .net designer how we drag and drop the controls ..so in my project i need to implement undo/Redo functionality..please give me the basic idea of this..(Please think like a our .net Designer (UNDO/REDO))
Thanks & regadrs
Dilip
|
|
|
|
|
Take a look at this blog[^], and see if it meets your needs.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I would personally have a structure which a) describes what the user did, or b) describes the state of the control before the user interacted. Then I would use a Stack, and just push or pop the structures whenever the user clicks Redo or Undo respectively (I think)
|
|
|
|
|
You may want to do some research into the "command pattern".
|
|
|
|
|
I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired.
Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine.
Any solution of this problem?
Thanks.
|
|
|
|
|
Maybe you could set a boolean flag which gets toggled when the user enters/leaves the textboxes on your form. The x key routine would then check the state of the boolean flag which would determine if the event should go ahead or not.
|
|
|
|
|
Thanks Liqz,
The situation is there is one main form and depending on menu items selection, it is loading user controls on main form, which comes from multiple solutions. So there are many solutions and lots of user controls are taking part here.
I do not want to change all the user controls but I want to change only main form.
Thanks.
|
|
|
|
|
Take a look at Tom's post below, it is actually a better solution than mine, I was unaware of the ActiveControl method.
Using that method you can get the type of the active control, then if the type of active control is a text box, don't do the x key function.
|
|
|
|
|
Use alt+x ?
Other than that in your function (that is called by the event handler on pressing x) check if the current active control is one where the user can type in (textbox, richtextbox,...)
This might be off help:
form.ActiveControl
|
|
|
|
|
Thanks Tom,
I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination.
Also I looked on ActiveControl but the deal is I have layers of controls like this:
Bottom to top
Form
User Control
Split control
User control
Textbox and other controls.
When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls.
Any help please?
Thanks.
|
|
|
|
|
Hi,
the KeyDown event offers a KeyEventArgs object containing information about the most recent key, but also the current state of the modifier keys such as Alt, Control, Shift.
|
|
|
|
|
If the alt+x way is a valid way to go for you I would do it that way, since you have usercontrols the activecontrol will most likly never be to accurate.
This code works fine for me:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt = True And e.KeyCode = Keys.X Then
MessageBox.Show("success")
End If
End Sub
Property 'Keypreview' from the form set to true
If you don't get it working like that I suggest you create a menustrip on the form, add a dummy menu, in the properties of that menu add a shortcut (alt + x), set the property 'visible' from the menustrip to false and do your function in the click event of the menu. (always works that way)
|
|
|
|
|
I am currently writing a program which allows users to crop an image by drawing a box on the displayed image. The control I am using is picture box. Now, the crop function is acheived by defining a rectangle and pass through Bitmap.Clone. all the cropping and saving function works fine, but the biggest problem I am having is the users I am working with deals with very high resolution images, somewhere in the lines of 2500 x 3500. Therefore to display the whole image onto the screen I am using either a SizeMode of Zoom or StretchImage, however this causes a problem when cropping the image. When the image is cropped it is not at the region specified by the rectangle, it ends up cropping a different portion of the image.
I cannot use SizeMode AtouSize either as the user must be able to see the entire image and the cropped area of the image must come from the original high resolution image. If anyone knows a solution to this problem or can point me to the right direction I would be most grateful.
Thanks in advance.
|
|
|
|
|
Hi,
the problem basically is that the PictureBox is doing things (panning, zooming, resizing, ...) to your image, and not to whatever you draw on top of it.
There are two solutions:
1. mimic the PictureBox logic for everything you are drawing on top of it.
2. don't use a PictureBox at all; use a Panel instead, show the image by painting it with Graphics.DrawImage; now implement the panning, zooming, resizing,... whatever you want yourself and apply them equally to the image and the other parts drawn (best use one or some of the Transform methods which manipulate coordinates and scales).
I always do (2), there is no benefit in trying to mimic a PictureBox when it works against you.
|
|
|
|
|