3ÆÄÆ®-14

Similar documents
3ÆÄÆ®-11


API STORE 키발급및 API 사용가이드 Document Information 문서명 : API STORE 언어별 Client 사용가이드작성자 : 작성일 : 업무영역 : 버전 : 1 st Draft. 서브시스템 : 문서번호 : 단계 : Docum

비긴쿡-자바 00앞부속

5장.key

02 C h a p t e r Java

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

PowerPoint 프레젠테이션

DocsPin_Korean.pages

rmi_박준용_final.PDF

Interstage5 SOAP서비스 설정 가이드

PowerPoint 프레젠테이션

05-class.key

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

01_피부과Part-01

PowerPoint 프레젠테이션

Microsoft PowerPoint - hci2-lecture12 [호환 모드]

Dialog Box 실행파일을 Web에 포함시키는 방법

1217 WebTrafMon II

Microsoft PowerPoint - Java7.pptx

PowerPoint 프레젠테이션

C H A P T E R 2

매뉴얼

Ext JS À¥¾ÖÇø®ÄÉÀ̼ǰ³¹ß-³¹Àå.PDF

PowerPoint 프레젠테이션

PowerPoint Presentation

초보자를 위한 자바 2 21일 완성 - 최신개정판

<4D F736F F F696E74202D E20C0CEC5CDB3DD20C0C0BFEB20B9D720BCADBAF1BDBA20B1E2BCFA E >

Microsoft PowerPoint - CSharp-10-예외처리

Microsoft PowerPoint - 04-UDP Programming.ppt

6강.hwp

자바 프로그래밍

Microsoft Word - Crackme 15 from Simples 문제 풀이_by JohnGang.docx

untitled

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

thesis-shk

Javascript.pages

12-file.key

자바-11장N'1-502

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

JMF3_심빈구.PDF

ch09

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

chapter4

(Microsoft PowerPoint - hci2-lecture12 [\310\243\310\257 \270\360\265\345])

09-interface.key

3장

초보자를 위한 C# 21일 완성

£01¦4Àå-2

½ºÅ丮ÅÚ¸µ3_³»Áö

272*406OSAKAÃÖÁ¾-¼öÁ¤b64ٽÚ

PART

Part Part

01....b

(291)본문7

¾Ë·¹¸£±âÁöħ¼�1-ÃÖÁ¾

2007백서-001-특집

00목차

JMF2_심빈구.PDF

0. 들어가기 전

untitled



2파트-07

untitled

SW

1 SW

03장.스택.key

01-OOPConcepts(2).PDF

bn2019_2

텀블러514

歯MW-1000AP_Manual_Kor_HJS.PDF

04장

C프로-3장c03逞풚

13주-14주proc.PDF

ibmdw_rest_v1.0.ppt

Java

PowerPoint Template


FileMaker ODBC and JDBC Guide

KISA-GD

Microsoft PowerPoint - CSharp-15-채팅

C++-¿Ïº®Çؼ³10Àå

초보자를 위한 ASP.NET 21일 완성

OCaml

KYO_SCCD.PDF

신림프로그래머_클린코드.key

KARAAUTO_4¿ù.qxd-ÀÌÆå.ps, page Normalize

학습목표 텍스트파일을다룰수있다. 스트림읽기, 쓰기를안다. 2

Secure Programming Lecture1 : Introduction

chap10.PDF

歯9장.PDF

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

chap7.key

<BACFC7D1B3F3BEF7B5BFC7E22D3133B1C733C8A BFEB2E687770>


Eclipse 와 Firefox 를이용한 Javascript 개발 발표자 : 문경대 11 년 10 월 26 일수요일

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

(Microsoft PowerPoint - C#\260\355\261\3361.ppt)

07 자바의 다양한 클래스.key

Transcription:

chapter 14 HTTP >>> 535

Part 3 _ 1 L i Sting using System; using System.Net; using System.Text; class DownloadDataTest public static void Main (string[] argv) WebClient wc = new WebClient(); byte[] response = wc.downloaddata(argv[0]); 536

Console.WriteLine(Encoding.ASCII.GetString(response)); C:\>DownloadDataTest http://localhost/test.htm <html> <title>this is a test web page</title> <body> <h1>this is a test web page</h1> </body> </html> C:\ > N o t e L i Sting using System; using System.Net; class DownloadFileTest 537

Part 3 _ public static void Main (string[] argv) WebClient wc = new WebClient(); string filename = "webpage.htm"; wc.downloadfile(argv[0], filename); Console.WriteLine("file downloaded"); C:\>DownloadFileTest http://localhost/test.htm file downloaded C:\>type webpage.htm <html> <title>this is a test web page</title> <body> <h1>this is a test web page</h1> </body> </html> C:\> L i Sting using System; using System.IO; using System.Net; class OpenReadTest public static void Main (string[] argv) 538

WebClient wc = new WebClient(); string response; Stream strm = wc.openread(argv[0]); StreamReader sr = new StreamReader(strm); while(sr.peek() > -1) response = sr.readline(); Console.WriteLine(response); sr.close(); L i Sting using System; using System.Collections.Specialized; using System.Net; class ResponseHeadersTest public static void Main (string[] argv) WebClient wc = new WebClient(); 539

Part 3 _ byte[] response = wc.downloaddata(argv[0]); WebHeaderCollection whc = wc.responseheaders; Console.WriteLine("header count = 0", whc.count); for (int i = 0; i < whc.count; i++) Console.WriteLine(whc.GetKey(i) + " = " + whc.get(i)); C:\>ResponseHeadersTest http://www.microsoft.com header count = 10 Date = Tue, 27 Aug 2002 04:06:34 GMT Server = Microsoft-IIS/6.0 P3P = CP='ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI' Content-Length = 31257 Content-Type = text/html Expires = Tue, 27 Aug 2002 18:06:34 GMT Cache-Control = private Age = 0 X-Cache = MISS from proxy.ispnet.net Proxy-Connection = keep-alive C:\ > 540

W a r ning OpenWrite(string URI); OpenWrite(string URI, string method); L i Sting using System; using System.IO; using System.Net; class OpenWriteTest public static void Main (string[] argv) WebClient wc = new WebClient(); string data = "Data up upload to server"; Stream strm = wc.openwrite(argv[0]); StreamWriter sw = new StreamWriter(strm); sw.writeline(data); sw.close(); strm.close(); 541

Part 3 _ UploadData(string URI, byte[] array); UploadData(string URI, string method, byte[] array); L i Sting using System; using System.Net; using System.Text; class UploadDataTest public static void Main (string[] argv) WebClient wc = new WebClient(); string data = "This is the data to post"; byte[] dataarray = Encoding.ASCII.GetBytes(data); wc.uploaddata(argv[0], dataarray); UploadFile(string URI, string filename); UploadFile(string URI, string method, string filename); 542

?lastname=blum &firstname=rich NameValueCollection nvc = new NameValueCollection(); nvc.add("lastname", "Blum"); nvc.add("firstname", "Rich"); byte[] response = wc.uploadvalues(uri, "POST", nvc); N o t e L i Sting using System; using System.Collection.Specialized; using System.Net; using System.Text; class UploadValuesTest public static void Main (string[] argv) WebClient wc = new WebClient(); string uri = "http://localhost/testform.aspx"; // 543

Part 3 _ NameValueCollection nvc = new NameValueCollection(); nvc.add("lastname", "Blum"); nvc.add("firstname", "Rich"); byte[] response = wc.uploadvalues(uri, nvc); Console.WriteLine(Encoding.ASCII.GetString(response)); NetworkCredential() NetworkCredential(string username, string password) NetworkCredential(string username, string password, string domain) 544

L i Sting using System; using System.Net; using System.Text; class CredTest public static void Main() WebClient wc = new WebClient(); NetworkCredential nc = new NetworkCredential("alex", "mypassword"); wc.credentials = nc; byte[] response = wc.downloaddata("http://localhost/testlogin"); Console.WriteLine(Encoding.ASCII.GetString(response)); Add(URI website, string authtype, NetworkCredential cred) 545

Part 3 _ L i Sting using System; using System.Net; using System.Text; class CredCacheTest public static void Main() WebClient wc = new WebClient(); string website1 = "http://remote1.ispnet.net"; string website2 = "http://remote2.ispnet.net"; string website3 = "http://remote3.ispnet.net/login"; NetworkCredential nc1 = new NetworkCredential("mike", "guitars"); NetworkCredential nc2 = new NetworkCredential ("evonne", "singing", "home"); NetworkCredential nc3 = new NetworkCredential("alex", "drums"); CredentialCache cc = new CredentialCache(); cc.add(new Uri(website1), "Basic", nc1); cc.add(new Uri(website2), "Basic", nc2); cc.add(new Uri(website3), "Digest", nc3); wc.credentials = cc; wc.downloadfile(website1, "website1.htm"); wc.downloadfile(website2, "website2.htm"); wc.downloadfile(website3, "website3.htm"); 546

2 HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(http://remotehost/webpage.htm); 547

Part 3 _ HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create( "http://remote1.ispnet2.net); WebProxy proxysrv = new WebProxy("http://proxy1.ispnet.net:2000"); hwr.proxy = proxysrv; HttpWebrequest hwr = (HttpWebRequest)WebRequest.Create("http://localhost"); Stream strm = hwr.getrequeststream(); StreamWriter sw = new StreamWriter(strm); sw.writeline(data); W a r ning 548

549

Part 3 _ String header = hwr.getresponseheader("x-cache"); HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create("http://www.amazon.com"); hwr.cookiecontainer = new CookieContainer(); HttpWebResponse hwrsp = (HttpWebResponse)hwr.GetResponse(); hwrsp.cookies = hwr.cookiecontainer.getcookies(hwr.requesturi); foreach(cookie cky in hwrsp.cookies) Console.WriteLine(cky.Name + " = " + cky.value); 550

L i Sting using System; using System.Drawing; using System.IO; using System.Net; using System.Windows.Forms; class WebGet : Form private TextBox uribox; private ListBox headers; private ListBox cookies; private ListBox response; public WebGet() Text = "WebGet - a web page retriever"; Size = new Size(500, 450); Label label1 = new Label(); label1.parent = this; label1.text = "URI:"; label1.autosize = true; label1.location = new Point(10, 23); uribox = new TextBox(); uribox.parent = this; uribox.size = new Size(200, 2 * Font.Height); uribox.location = new Point(35, 20); Label label2 = new Label(); label2.parent = this; label2.text = "Headers:"; label2.autosize = true; label2.location = new Point(10, 46); 551

Part 3 _ headers = new ListBox(); headers.parent = this; headers.horizontalscrollbar = true; headers.location = new Point(10, 65); headers.size = new Size(450, 6 * Font.Height); Label label3 = new Label(); label3.parent = this; label3.text = "Cookies:"; label3.autosize = true; label3.location = new Point(10, 70 + 6 * Font.Height); cookies = new ListBox(); cookies.parent = this; cookies.horizontalscrollbar = true; cookies.location = new Point(10, 70 + 7 * Font.Height); cookies.size = new Size(450, 6 * Font.Height); Label label4 = new Label(); label4.parent = this; label4.text = "HTML:"; label4.autosize = true; label4.location = new Point(10, 70 + 13 * Font.Height); response = new ListBox(); response.parent = this; response.horizontalscrollbar = true; response.location = new Point(10, 70 + 14 * Font.Height); response.size = new Size(450, 12 * Font.Height); Button sendit = new Button(); sendit.parent = this; sendit.text = "GetIt"; sendit.location = new Point(275, 18); sendit.size = new Size(7 * Font.Height, 2 * Font.Height); sendit.click += new EventHandler(ButtongetitOnClick); void ButtongetitOnClick(object obj, EventArgs ea) headers.items.clear(); cookies.items.clear(); response.items.clear(); 552

HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(uribox.Text); hwr.cookiecontainer = new CookieContainer(); HttpWebResponse hwrsp = (HttpWebResponse)hwr.GetResponse(); WebHeaderCollection whc = hwrsp.headers; for (int i = 0; i < whc.count; i++) headers.items.add(whc.getkey(i) + " = " + whc.get(i)); hwrsp.cookies = hwr.cookiecontainer.getcookies(hwr.requesturi); foreach(cookie cky in hwrsp.cookies) cookies.items.add(cky.name + " = " + cky.value); Stream strm = hwrsp.getresponsestream(); StreamReader sr = new StreamReader(strm); while (sr.peek() > -1) response.items.add(sr.readline()); sr.close(); strm.close(); public static void Main() Application.Run(new WebGet()); 553

Part 3 _ W a r ning 3 N o t e 554

555

Part 3 _ L i Sting <%@ WebService Language="c#" Class="MathService"%> using System; using System.Web.Services; [WebService(Namespace="http://localhost/test")] public class MathService : WebService [WebMethod] public int Add(int a, int b) int answer; answer = a + b; return answer; [WebMethod] public int Subtract(int a, int b) int answer; answer = a - b; return answer; [WebMethod] public int Multiply(int a, int b) int answer; answer = a * b; return answer; [WebMethod] public int Divide(int a, int b) int answer; if (b!= 0) answer = a / b; return answer; else return 0; 556

<%@ WebService Language="c#" Class="MathService"%> [WebService(Namespace=http://localhost/test)] C:\Inetpub\wwwroot\test\MathService.asmx 557

Part 3 _ C:\>wsdl http://localhost/test/mathservice.asmx csc /t:library MathService.cs 558

L i Sting using System; class ServiceTest public static void Main (string[] argv) MathService ms = new MathService(); int x = Convert.ToInt16(argv[0]); int y = Convert.ToInt16(argv[1]); int sum = ms.add(x, y); int sub = ms.subtract(x, y); int mult = ms.multiply(x, y); int div = ms.divide(x, y); Console.WriteLine("The answers are:"); Console.WriteLine(" 0 + 1 = 2", x, y, sum); Console.WriteLine(" 0-1 = 2", x, y, sub); Console.WriteLine(" 0 * 1 = 2", x, y, mult); Console.WriteLine(" 0 / 1 = 2", x, y, div); csc /r:mathservice.dll ServiceTest.cs 559

Part 3 _ C:\>ServiceTest 100 50 The answers are: 100 + 50 = 150 100-50 = 50 100 * 50 = 5000 100 / 50 = 2 C:\> 4 560

561