<system.web>
<httpRuntime requestValidationMode="2.0" maxRequestLength="1024000"/>
</system.web>
public string UploadFilesToRemoteUrl(string url, string[] files, NameValueCollection formFields = null)
{
string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "multipart/form-data; boundary=" +
boundary;
request.Method = "POST";
request.KeepAlive = true;
Stream memStream = new System.IO.MemoryStream();
var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
boundary + "\r\n");
var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
boundary + "--");
string formdataTemplate = "\r\n--" + boundary +
"\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";
if (formFields != null)
{
foreach (string key in formFields.Keys)
{
string formitem = string.Format(formdataTemplate, key, formFields[key]);
byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
memStream.Write(formitembytes, 0, formitembytes.Length);
}
}
string headerTemplate =
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
"Content-Type: application/octet-stream\r\n\r\n";
for (int i = 0; i < files.Length; i++)
{
memStream.Write(boundarybytes, 0, boundarybytes.Length);
var header = string.Format(headerTemplate, "uplTheFile", files[i]);
var headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
memStream.Write(headerbytes, 0, headerbytes.Length);
using (var fileStream = new FileStream(files[i], FileMode.Open, FileAccess.Read))
{
var buffer = new byte[1024];
var bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
Response.Write("bytesRead: " + bytesRead.ToString() + "<br>");
memStream.Write(buffer, 0, bytesRead);
}
}
}
memStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
request.ContentLength = memStream.Length;
using (Stream requestStream = request.GetRequestStream())
{
memStream.Position = 0;
byte[] tempBuffer = new byte[memStream.Length];
memStream.Read(tempBuffer, 0, tempBuffer.Length);
memStream.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
}
try
{
using (var response = request.GetResponse())
{
Stream stream2 = response.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
return reader2.ReadToEnd();
}
}
catch (Exception ex)
{
return (ex.ToString());
throw;
}
}
namespace WWW.Controllers
{
public class UploadController : Controller
{
// GET: Upload
public void Index(string Filename)
{
//Create a stream for the file
Stream stream = null;
//This controls how many bytes to read at a time and send to the client
int bytesToRead = 10000;
// Buffer to read bytes in chunk size specified above
byte[] buffer = new Byte[bytesToRead];
string url = "http://admin-dev.nanya.bike.idv.tw/newnanyaback/Upload/" + Filename;
// The number of bytes read
try
{
//Create a WebRequest to get the file
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(url);
//Create a response for this request
HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
if (fileReq.ContentLength > 0)
fileResp.ContentLength = fileReq.ContentLength;
//Get the Stream returned from the response
stream = fileResp.GetResponseStream();
// prepare the response to the client. resp is the client Response
var resp = HttpContext.Response;
if (Filename.ToLower().EndsWith(".png") ||
Filename.ToLower().EndsWith(".jpg") ||
Filename.ToLower().EndsWith(".jpeg") ||
Filename.ToLower().EndsWith(".gif")
)
{
resp.ContentType = "image";
}
else
{
//Indicate the type of data being sent
resp.ContentType = "application/octet-stream";
//Name the file
resp.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(Filename, Encoding.UTF8) + "\"");
}
resp.AddHeader("Content-Length", fileResp.ContentLength.ToString());
int length;
do
{
// Verify that the client is connected.
if (resp.IsClientConnected)
{
// Read data into the buffer.
length = stream.Read(buffer, 0, bytesToRead);
// and write it out to the response's output stream
resp.OutputStream.Write(buffer, 0, length);
// Flush the data
resp.Flush();
//Clear the buffer
buffer = new Byte[bytesToRead];
}
else
{
// cancel the download if client has disconnected
length = -1;
}
} while (length > 0); //Repeat until no data is read
}
finally
{
if (stream != null)
{
//Close the input stream
stream.Close();
}
}
}
}
}
System.Web.HttpContext.Current.Response.Write("location.reload()" & vbCrLf)
System.Web.HttpContext.Current.Response.Write("location.href=location.href" & vbCrLf)
Response.Cache.SetCacheability(HttpCacheability.Private)
Response.Cache.SetExpires(Now.AddYears(1)) '一年後才會到期,沒有這個就不會有 200 (From Cache)
Response.Cache.SetLastModified(Now) '若是 Browser 送出了一個新的 Request, 有可能會回 304
//先檢查是不是已經登入
FB.getLoginStatus(function (response) {
if (response.status === "connected") {
// 已登入FB
}
else {
// 未登入FB
// 盡量不要在此呼叫 FB.login , 因為彈跳視窗會被擋下來
}
});
//呼叫登入 scope:publish_stream 是要讓user同意發文到FB的權限
FB.login(function (response) {
if (response.authResponse) {
// 已登入,可取得 AccessToken
} else {
// 未登入
}
}, { scope: 'publish_stream' });
// 檢查 user 有無同意發文到FB的權限 (publish_stream)
FB.api({ method: 'users.hasAppPermission', ext_perm: 'publish_stream' }, function (resp) {
if (resp === "1") {
//有同意
} else {
//不同意
}
});
// 分享連結到登入者的FB牆
// msg 是發文的內容
// link, picture, caption, description 是一組的
var args = {
message: msg,
link: product.Link,
picture: product.Picture,
caption: product.Name,
description: "超高口碑BB霜/CC霜、頂級精華液哪款半價 由你決定!"
};
FB.api('/me/feed', 'post', args, function (response) {
if (response.id) {
// 成功會回傳訊息id
}
else {
// 分享失敗
}
});
FB.ui({
method: 'feed',
name: '快去搶!超過9成的使用者滿意推薦的《玻尿酸精華》',
link: 'http://www.shopunt.com/tch/event/2014-aqua-deluge/default.aspx',
picture: 'http://www.shopunt.com/Upload/tch/unt/14mar/fb154x154.jpg',
caption: 'UNT 頂級玻尿酸保濕精華液(奢華)',
description: '熱銷破百萬 真實口碑見證的水感奇肌 逆時補水科技 快速滲透 為肌膚注入高水位……'
},
function (response) {
if (response && response.post_id) {
// handle success
}
else {
alert("facebook分享失敗!");
}
}
);
Inherits Master
Protected Sub Page_PreLoad(sender As Object, e As EventArgs) Handles Me.PreLoad
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
HandleAction()
End Sub
Sub HandleAction()
If UW.WU.IsNonEmptyFromQueryStringOrForm("Action") Then
Dim Action As String = UW.WU.GetValueFromQueryStringOrForm("Action")
Select Case Action
End Select
End If
End Sub
Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
LoadPageContext()
End Sub
Sub LoadPageContext()
End Sub
Sub JSONWriteToClient(ByVal TrueorFalse As Boolean, Optional ByVal msg As String = "", Optional ByVal Title As String = "", Optional ByVal Content As String = "", Optional ByVal Content2 As String = "", Optional ByVal Content3 As String = "")
Dim TF As String = Now.ToString("yyyyMMddHHmmss")
Dim oJ As UW.JSON
oJ = New UW.JSON(TrueorFalse, msg)
oJ.add("Title", Title)
oJ.add("Content", Content)
oJ.add("Content2", Content2)
oJ.add("Content3", Content3)
oJ.add("TF", TF)
oJ.WriteToClient()
Response.End()
End Sub
Dim d As Date = Now
Dim n As Decimal = 86400.99
Dim Cultures() As String = {"zh-TW", "pt-BR", "pt-PT", "en-US", "en-GB", "fr-FR", "de-DE", "es-ES", "ja-JP", "zh-CN", "ko-KR", "en-IN"}
For i As Integer = 0 To Cultures.GetUpperBound(0)
Dim c As New Globalization.CultureInfo(Cultures(i))
Response.Write(Cultures(i) & "<br/>" & d.ToString("D", c) & " <br/>" & d.ToString("d", c) & "<br/>" & n.ToString("C", c))
Response.Write("<hr/>")
Next
zh-TW
2013年12月25日
2013/12/25
NT$86,400.99
pt-BR
quarta-feira, 25 de dezembro de 2013
25/12/2013
R$ 86.400,99
pt-PT
quarta-feira, 25 de Dezembro de 2013
25-12-2013
86.400,99 €
en-US
Wednesday, December 25, 2013
12/25/2013
$86,400.99
en-GB
25 December 2013
25/12/2013
£86,400.99
fr-FR
mercredi 25 décembre 2013
25/12/2013
86 400,99 €
de-DE
Mittwoch, 25. Dezember 2013
25.12.2013
86.400,99 €
es-ES
miércoles, 25 de diciembre de 2013
25/12/2013
86.400,99 €
ja-JP
2013年12月25日
2013/12/25
¥86,401
zh-CN
2013年12月25日
2013/12/25
¥86,400.99
ko-KR
2013년 12월 25일 수요일
2013-12-25
₩86,401
en-IN
25 December 2013
25-12-2013
₹ 86,400.99