之前在做一个小项目,C#的,最后需要生成.mid的MIDI文件。网上找了很多资料,大部分都是读取,没有写入。嗯我承认其实读取反过来就是写入。但是没有封装好的类好麻烦的。。
突然看到了MidiShow的在线编辑功能,眼前一亮,想到了用来写网页的PHP。于是我就百度了,找到了一个类库。项目里模拟http请求去调用它。现在放出来,一是以后备查,二是也希望方便大家。
API说明及测试页:https://player.pocketcraft.bid/midi/api/
服务器弱,经不住攻击,各位手下留情。
以下是从互联网上找到的关于POST上传文件的代码,希望能对你有所启发
C# 摘自:http://www.cnblogs.com/password1/p/5870725.html
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Net;
namespace HuaTong.General.Utility
{
/// <summary>
/// 用于模拟POST上传文件到服务器
/// </summary>
public class HttpUpload
{
private ArrayList bytesArray;
private Encoding encoding = Encoding.UTF8;
private string boundary = String.Empty;
public HttpUpload()
{
bytesArray = new ArrayList();
string flag = DateTime.Now.Ticks.ToString("x");
boundary = "---------------------------" + flag;
}
/// <summary>
/// 合并请求数据
/// </summary>
/// <returns></returns>
private byte[] MergeContent()
{
int length = 0;
int readLength = 0;
string endBoundary = "--" + boundary + "--\r\n";
byte[] endBoundaryBytes = encoding.GetBytes(endBoundary);
bytesArray.Add(endBoundaryBytes);
foreach (byte[] b in bytesArray)
{
length += b.Length;
}
byte[] bytes = new byte[length];
foreach (byte[] b in bytesArray)
{
b.CopyTo(bytes, readLength);
readLength += b.Length;
}
return bytes;
}
/// <summary>
/// 上传
/// </summary>
/// <param name="requestUrl">请求url</param>
/// <param name="responseText">响应</param>
/// <returns></returns>
public bool Upload(String requestUrl,