【原】借鸡生蛋 C# 转 VB 和 C# 转 VB 【有源码】

阅读: 评论:0

【原】借鸡生蛋 C# 转 VB 和 C# 转 VB 【有源码】

【原】借鸡生蛋 C# 转 VB 和 C# 转 VB 【有源码】

思路:模拟数据提交,分析回发数据,提取结果。

我们先看这个网站,

/  【Convertor】

打开 【Convertor】 的站点,使用firebug 或 httpwatch 分析出post 数据,这里请参考如下代码:

AutomaticClipboard=ture&AutomaticClipboard=false&Code=" + code

上一行代码很重要,目的是为了模拟提交数据, 再看这行,

 StreamReader responseStream = new StreamReader(request.GetResponse().GetResponseStream());


这行代码目的是得到回发数据,好了,其他就不多说了,贴代码:

 

CONVERTOR
<%@ Page Language="C#" ValidateRequest="false" %>

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace=" System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">

<script runat="server">
    protected void btnConvert_Click(object sender, EventArgs e)
    {
        string url = "/";
        WebRequest request = HttpWebRequest.Create(url);
        request.Method = "post";
        string code = txtCode.Text.Trim();
        request.ContentType = "application/x-www-form-urlencoded";
        string postedData = "AutomaticClipboard=ture&AutomaticClipboard=false&Code=" + code;
        byte[] requestContent = System.Text.Encoding.ASCII.GetBytes(postedData);
        request.ContentLength = requestContent.Length;
        Stream requestStream = request.GetRequestStream();
        requestStream.Write(requestContent, 0, requestContent.Length);
        //read the response;
        StreamReader responseStream = new StreamReader(request.GetResponse().GetResponseStream());
        string response = responseStream.ReadToEnd();
        responseStream.Close();
        int firstdiv = response.IndexOf("<ul", response.IndexOf("code-view"));
        int lastdiv = response.IndexOf("</ul>", firstdiv);
        string result = response.Substring(firstdiv, lastdiv - firstdiv);
        ltlResult.Text = result;

    } 
</script>

<html xmlns="">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtCode" runat="server" Height="204px" TextMode="MultiLine" Width="586px"></asp:TextBox>
        <br />
        <asp:Button ID="btnConvert" runat="server" OnClick="btnConvert_Click" Text="Convert" />
        <br />
        <asp:Literal ID="ltlResult" runat="server"></asp:Literal>
    </div>
    </form>
</body>
</html>

当然其实网上还有有很多C#和VB.NET互转工具:

http: // uk/convert/csharp-to-vb.aspx
http: // dechanger/
http: // www.dotnetspider/convert/Vb-To-Csharp.aspx
http: // www.kamalpatel/
http: // csharpconverter.claritycon
http: // www.ragingsmurf/
http: // aspalliance/
http: // developerfusion/
www.icsharpcode
http: // blogs.msdn/goto100/archive/2008/07/23/converting-from-c-to-visual-basic-net.aspx

当然你有更好的方法也可以告知,谢谢了先!

转载于:.html

本文发布于:2024-02-04 23:59:25,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170719371360949.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:借鸡生蛋   源码   VB
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23