 |
ใช้ฟังชั่น cUrl Login เข้าเว็บที่เป็น asp.net แล้วมันขึ้น System.FormatException: Invalid character in a Base-64 string. |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Public Sub DecodeWithString()
Dim inFile As System.IO.StreamReader
Dim base64String As String
Try
Dim base64CharArray() As Char
inFile = New System.IO.StreamReader(inputFileName, _
System.Text.Encoding.ASCII)
base64CharArray = New Char(inFile.BaseStream.Length) {}
inFile.Read(base64CharArray, 0, inFile.BaseStream.Length)
base64String = New String(base64CharArray, _
0, _
base64CharArray.Length - 1)
Catch exp As System.Exception
' Error creating stream or reading from it.
System.Console.WriteLine("{0}", exp.Message)
Return
End Try
' Convert the Base64 UUEncoded input into binary output.
Dim binaryData() As Byte
Try
binaryData = System.Convert.FromBase64String(base64String)
Catch exp As System.ArgumentNullException
System.Console.WriteLine("Base 64 string is null.")
Return
Catch exp As System.FormatException
System.Console.WriteLine("Base 64 length is not 4 or is " + _
"not an even multiple of 4.")
Return
End Try
'Write out the decoded data.
Dim outFile As System.IO.FileStream
Try
outFile = New System.IO.FileStream(outputFileName, _
System.IO.FileMode.Create, _
System.IO.FileAccess.Write)
outFile.Write(binaryData, 0, binaryData.Length - 1)
outFile.Close()
Catch exp As System.Exception
' Error creating stream or writing to it.
System.Console.WriteLine("{0}", exp.Message)
End Try
End Sub
http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx
|
 |
 |
 |
 |
Date :
2011-11-21 06:31:30 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ แต่ยัง งงนะครับ
ผมต้อง เอา ViewState นี้ไปเข้ารหัส ก่อนส่งค่า form ไปหรือป่าว ครับ
code ครับ
Code (PHP)
<?php // สร้าง cookie
$cookie_file_path = "/path/to/cookie.txt";
$LOGINURL = "http://www.example.com/login.aspx";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
// ทำการ login
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
unset($ch);
// ค้นหา view state ปัจจุบัน
preg_match('/<input type="hidden" name="__VIEWSTATE" value="([^";]*?)"; \/>/', $result, $matches);
$viewstate = $matches[1];
$viewstate = urlencode($viewstate);
//ทำการเรียกใช้งานฟังก์ชั่นที่ต้องการ
$POSTURL = "http://www.example.com/main.aspx";
$reffer = "http://www.example.com/main.aspx";
$POSTFIELDS = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=$viewstate&txtARG1=$arg1&txtARG2=$arg2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$POSTURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
unset($ch);
echo $result;
// ค้นหา view state ปัจจุบัน
preg_match('/<input type="hidden"; name="__VIEWSTATE" value="([^"]*?)"; \/>/', $result, $matches);
$viewstate = $matches[1];
$viewstate = urlencode($viewstate);
//Log out
$LOGOFFURL = "http://www.example.com/logOff.aspx";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGOFFURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
unset($ch);
?>
|
ประวัติการแก้ไข 2011-11-21 08:18:44
 |
 |
 |
 |
Date :
2011-11-21 08:18:02 |
By :
diewd2a |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|