반응형
string _return = "false";

StringBuilder UrlEncoded = new StringBuilder();
byte[] SomeBytes = null;
int leng = 1024;
char[] buffer = new char[leng];

WebRequest request = WebRequest.Create("http://서블릿 주소");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//자바서블릿에 정의된 파라미터를 위한 처리부분
UrlEncoded.Append("?javanet=none");
for (int i=0; i<_param.Length/2; i++) 
{
UrlEncoded.Append("&"+_param[0,i]+"="+_param[1,i]);
}

SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
request.ContentLength = SomeBytes.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();

WebResponse res = request.GetResponse();

StreamReader sr = new StreamReader(res.GetResponseStream(),System.Text.Encoding.Default);

int count = 0;
string tmpVal = "";
do
{
count = sr.Read(buffer,0,leng);
tmpVal += new string(buffer,0,count);
}while(count>0);
sr.Close();
//자바서블릿에서 처리된 결과를 반환
_return = tmpVal.Trim();
return _return;
반응형
using System.Web.Mail;

private void SmtpMailSend()
{
MailMessage mail = new MailMessage();
mail.From = "보내는 사람";
mail.To = "받는사람";
mail.Cc = "참조";

mail.Subject = "메일 제목";
mail.Body = "메일 본문 내용";
mail.BodyFormat = MailFormat.Html; //메일 Fotmat 형식
mail.Priority = MailPriority.High; //메일 중요도
SmtpMail.Send(mail); //메일 발송
}

반응형
//--------------------서버주소 가져오기-----------------------------------

using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;

IPHostEntry IPHost = Dns.Resolve(Dns.GetHostName());
IPAddress addr = IPHost.AddressList[0];
IPHost.AddressList[0].ToString();

==================↓한줄요약===================================
IPAddress addr = Dns.Resolve(Dns.GetHostName()).AddressList[0];

//--------------------클라이언트 주소가져오기-----------------------------

Response.Write(Request.ServerVariables["REMOTE_HOST"]);
반응형
//========================================
//↓↓ASP.NET1.1에서 파일업로드
//========================================
protected void saveFile()
{
    string FileName = FileUpload.PostedFile.FileName;
    if (FileName != null || FileName != string.Empty)
    {
        Session["myupload"] = FileUpload;
    }
    HtmlInputFile hif = (HtmlInputFile)Session["myupload"];
    string storePath = "d:\\momo13";
    if (Directory.Exists(storePath))
        Directory.CreateDirectory(storePath);
    hif.PostedFile.SaveAs(storePath + "/" + Path.GetFileName(hif.PostedFile.FileName));
    lblMsg.Text = "업로드";
}

//========================================
//↓↓ASP.NET2.0에서 파일업로드
//========================================
protected void saves1()
{
    if (FileUpload1.HasFile)
    {
        
        DirectoryInfo di = new DirectoryInfo(upDir);
        if (!di.Exists)
            di.Create();
        string fName = FileUpload1.FileName;
        string fFullName = upDir + fName;
        FileInfo fInfo = new FileInfo(fFullName);
        if (fInfo.Exists)
        {
            int fIndex = 0;
            string fExtension = fInfo.Extension;
            string fRealName = fName.Replace(fExtension, "");
            string newFileName = "";
            do
            {
                fIndex++;
                newFileName = fRealName + "_" + fIndex.ToString() + fExtension;
                fInfo = new FileInfo(upDir + "\\" + newFileName);
            }
            while (fInfo.Exists);
            fFullName = upDir + "\\" + newFileName;
        }
        FileUpload1.PostedFile.SaveAs(fFullName);
        lblMsg.Text = "업로드된 파일 : " + fFullName;
    }
    else
    {
        lblMsg.Text = "업로드할 파일이 존재하지 않습니다.";
    }
}

반응형
string strSql = "Select * From country_def";
OracleCommand cmd = new OracleCommand(strSql,dbConn.OraConn());
cmd.Connection.Open();
OracleDataReader rd = cmd.ExecuteReader();
dpCountry.DataSource = rd;
dpCountry.DataValueField = "country_cd";
dpCountry.DataTextField = "country_name";
dpCountry.DataBind();
rd.Close();
cmd.Connection.Close();
----------------------------------------------------------------------
기초적인 내용인데 자주 까먹는다. ㅠ_ㅠ
반응형
ASP.NET에서는 Response.WriteFile() 이라는 함수를 이용해서 파일(바이너리)을 스트림으로 내려보낼 수 있다.
사용 방법은 간단하다.

 

    Response.AddHeader("Content-Disposition", "attachment;filename=\"123.zip\"");
    Response.ContentType = "application/octet-stream";

    Response.WriteFile("C:\\123.zip");

 

즉, URL로 접근이 가능하지 않은 파일을 이와 같은 방법을 통해 동적으로 내려보낼 수 있다.
그런데, 이 파일의 크기가 100MB이상의 대용량인 경우에는 웹 서버에서 에러가 발생하고 다운로드가 안될 수 있다.
그럴 때는 아래 링크를 참조하자.

 

http://support.microsoft.com/kb/812406 

반응형
※닷넷에서 한글파라미터는 인식이 되지 않는 경우가 있기 때문에 인코딩 디코딩 해준다.
   특히 띄워쓰기 포함된 한글파라미터는 반드시 인코딩 디코딩 해주어야 한다.

//보내는 쪽 url파라미터
group = HttpUtility.UrlEncode(group);
//받는 쪽 url파라미터
group = HttpUtility.UrlDecode(Request.Params["group"].ToString().Trim());

※참조한 원문 
HttpUtility.UrlEncode("홍길동", System.Text.Encoding.GetEncoding("euc-kr")) 

+ Recent posts